Step 4.2. Loading data to the scheduler

Step 4.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. And all that we should do in the action is to apply these classes in order to display the list of tasks from the Tasks database table in the Manager.aspx view. The list of tasks is assigned to a local variable named tasks that is passed to the view through SchedulerAjaxData() method.

Your actions:

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

    public ActionResult Data() {
            if (RoleIs("Manager"))
                var context = new TasksDataContext();
                var tasks = from ts in context.Tasks
                             join stat in context.Statuses on ts.status_id equals stat.key
                             select new { stat.color,, ts.owner_id, ts.details,
                                      ts.end_date, ts.start_date, ts.text, ts.status_id };
                var resp = new SchedulerAjaxData(tasks);
                return resp;
                return new SchedulerAjaxData();////if the user is not authorized or not in the Manager Role, returns the empty dataset

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

comments powered by Disqus