Step 5.4. CRUD logic

Step 5.4. CRUD logic

Skip and go to the next step

On this step we must specify how employees data requests will be proccessed and send back to the server. As employees can change just the status of tasks, we should define how the request on a status update will be processed.
Anytime we need to work with the database, we need to use LINQ to SQL classes, i.e. TasksDataContext.

In the end we will return the Index() action that redirects us to the Employee view.

Your actions:

  1. Move to Solution Explorer→Controllers and open the SystemController.cs file.
  2. Add the UpdateStatus action to the existing code of the file:
public ActionResult UpdateStatus(int? id) {
      if (RoleIs("Employee") && this.Request.Form["result"] == "Update" && id != null)
           TasksDataContext data = new TasksDataContext();
           Task task = data.Tasks.SingleOrDefault(ev => == id);
           if (task != default(Task) || task.owner_id == (Guid)Membership.GetUser().ProviderUserKey)
               task.status_id = int.Parse(this.Request.Form["status_id"]);
       return RedirectToAction("Index", "System");

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

comments powered by Disqus