Step 5.3. Activating the details form

Step 5.3. Activating the details form

Skip and go to the next step

In the Manager view for editing tasks we use the built-in lightbox. For employees we can't use such the form cause they aren't allowed to editing.

So, we must create a new details form, specially for Employee users. About view for the details form we will talk on the next step (Step 6) and now you will be known how to implement the action that will return this view. Also on this step, a new model class must be created. It will be needed to us for passing details of the currently selected task to the view.

This action will contain:

  • rights checking region (we used it throughout all actions);
  • loading details of the selected task. Here, we will again use LINQ to SQL class - TasksDataContext;

Your actions:

  1. Move to Solution Explorer→Models and create a new file there. Name it TaskDetails.cs.
  2. Put the code below into it:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    namespace TaskManagementSystem.Models
        public class TaskDetails
            public Task Task{ get; set; }
            public IEnumerable<Statuse> Statuses { get; set; }
            public TaskDetails(Task ts, IEnumerable<Statuse> st)
                Task = ts;
                Statuses = st;
  3. Move to Solution Explorer→Controllers and open the SystemController.cs file.
  4. Add the TaskDetails action to the existing code of the file:

    public ActionResult TaskDetails(int? id) {
        #region check rights
            if (!RoleIs("Employee"))
                return RedirectToAction("Index", "System");
                TasksDataContext data = new TasksDataContext();
                Task task = default(Task);
                if (id != null)
                    task = (from t in data.Tasks where == id select t).FirstOrDefault();
                    if(task.owner_id != (Guid)Membership.GetUser().ProviderUserKey)
                        task = default(Task);
                var statuses = data.Statuses.ToArray();
                ViewData["status"] = task != default(Task) ? task.status_id : statuses[0].key;
                ViewData["user"] = User.Identity.Name;
                return View(new TaskDetails(task, statuses ));

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

comments powered by Disqus