public ActionResult Edit(int?id)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.ProjectTask))
            {
                return(RedirectToPermissionDenied());
            }

            // Check if a project task ID was provided
            if (id == null)
            {
                return(RedirectToIndex());
            }
            int projectTaskId = (int)id;

            // Entry try-catch from here
            // Make sure any errors are displayed
            try
            {
                // Get the project task data
                var projectTaskModel = ProjectTaskProcessor.GetProjectTask(projectTaskId);
                if (projectTaskModel == null)
                {
                    return(RedirectToIndexIdNotFound(projectTaskId));
                }

                // Convert the model data to non-model data
                var projectTask = new ProjectTask(projectTaskModel)
                {
                    // Fill in missing text data
                    StudentUsername = UserProcessor.SelectUserForEnrollment(projectTaskModel.EnrollmentId)?.Username
                };

                // Get all possible roles which could be assigned to this task
                var projectRoles = ProjectRoleProcessor.GetProjectRolesForEnrollment(projectTaskModel.EnrollmentId);

                // Setup the project role drop-down list
                SetupRoleDropDownList(projectRoles, projectTask.ProjectRoleId);

                // Pass the data to the view
                return(View(projectTask));
            }
            catch (Exception e)
            {
                return(RedirectToIndex(e));
            }
        }
        public ActionResult Edit(ProjectTask projectTask)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.ProjectTask))
            {
                return(RedirectToPermissionDenied());
            }

            // Make sure the entered data is valid
            if (ModelState.IsValid)
            {
                // Update the project task within the database
                try
                {
                    ProjectTaskProcessor.UpdateProjectTask(
                        projectTask.ProjectTaskId,
                        projectTask.Description,
                        projectTask.ProjectRoleId,
                        projectTask.Duration);
                    TempData[LabelSuccess] = "Updated task.";
                    return(RedirectToIndex());
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", e.Message);
                }
            }
            else
            {
                //show error
                var errors = ModelState.Values.SelectMany(v => v.Errors);
            }

            // Get all possible roles which could be assigned to this task
            var projectRoles = ProjectRoleProcessor.GetProjectRolesForEnrollment(projectTask.EnrollmentId);

            // Setup the project role drop-down list
            SetupRoleDropDownList(projectRoles, projectTask.ProjectRoleId);

            // Return to same page with same data
            return(View(projectTask));
        }