Step 5.2. Loading data to the scheduler

Step 5.2. Loading data to the scheduler

Skip and go to the next step

On the Step 3 we created LINQ to SQl classes to retrieve data from the database. Now we'll apply these classes to display tasks from the Tasks database table in the Employee.aspx view. We will load just the tasks assigned to the currently logged in user. The list of tasks is assigned to a local variable named tasks that is passed to the view through the SchedulerAjaxData() method.

Your actions:

  1. Move to Solution Explorer→Controllers and open the SystemController.cs file.
  2. Add the following code to the existing content of the file:

    public ActionResult Tasks() {
        #region check rights
                if (!RoleIs("Employee"))
                    return new SchedulerAjaxData();//returns the empty dataset
                var context = new TasksDataContext();
                var tasks = from t in context.Tasks
                            join stat in context.Statuses on t.status_id equals stat.key
                            where t.owner_id == (Guid)Membership.GetUser().ProviderUserKey
                            select new { stat.color,, t.owner_id, t.details,
                                    t.end_date, t.start_date, t.text, t.status_id };
                var resp = new SchedulerAjaxData(tasks);
                return resp;

    RoleIs() is the function that we defined on the step 3 (sub-step 3.2.3).

comments powered by Disqus