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

            // Set the page message
            ViewBag.Message = "Project Role List";

            // Get all project roles from the database
            var projectRoleModels = ProjectRoleProcessor.GetAllProjectRoles();

            // Convert the list to the correct type
            List <ProjectRole> projectRoles = new List <ProjectRole>();

            foreach (var p in projectRoleModels)
            {
                projectRoles.Add(new ProjectRole(p));
            }

            // Return the view, with the list of project roles
            return(View(projectRoles));
        }
        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(int?id)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.ProjectRoleGroup))
            {
                return(RedirectToPermissionDenied());
            }

            // Check if a project role group ID was provided
            if (id == null)
            {
                return(RedirectToIndex());
            }
            int projectRoleGroupId = (int)id;

            // Entry try-catch from here
            // Make sure any errors are displayed
            try
            {
                // Get the project role group data
                var projectRoleGroupModel = ProjectRoleGroupProcessor.GetProjectRoleGroup(projectRoleGroupId);
                if (projectRoleGroupModel == null)
                {
                    return(RedirectToIndexIdNotFound(projectRoleGroupId));
                }

                // Convert the model data to non-model data
                ProjectRoleGroup projectRoleGroup = new ProjectRoleGroup(projectRoleGroupModel);

                // Get list of all project roles
                var projectRoleModels = ProjectRoleProcessor.GetAllProjectRoles();

                // Get the links which are assigned to this group
                projectRoleGroup.Links = GetLinksForGroup(projectRoleGroup.ProjectRoleGroupId, projectRoleModels);

                // Setup the dropdown list with all project roles
                SetupRoleDropDownList(projectRoleModels);

                // Pass the data to the view
                return(View(projectRoleGroup));
            }
            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));
        }
        public ActionResult Edit(int?id)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.ProjectRole))
            {
                return(RedirectToPermissionDenied());
            }

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

            // Entry try-catch from here
            // Make sure any errors are displayed
            try
            {
                // Get the project role data
                var projectRoleModel = ProjectRoleProcessor.GetProjectRole(projectRoleId);
                if (projectRoleModel == null)
                {
                    return(RedirectToIndexIdNotFound(projectRoleId));
                }

                // Convert the model data to non-model data
                // Pass the data to the view
                return(View(new ProjectRole(projectRoleModel)));
            }
            catch (Exception e)
            {
                return(RedirectToIndex(e));
            }
        }
        public ActionResult Edit(ProjectRole projectRole)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.ProjectRole))
            {
                return(RedirectToPermissionDenied());
            }

            // Make sure the entered data is valid
            if (ModelState.IsValid)
            {
                // Update the project role within the database
                try
                {
                    ProjectRoleProcessor.UpdateProjectRole(
                        projectRole.ProjectRoleId,
                        projectRole.Name);
                    TempData[LabelSuccess] = "Updated role: " + projectRole.Name;
                    return(RedirectToIndex());
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", e.Message);
                }
            }
            else
            {
                //show error
                var errors = ModelState.Values.SelectMany(v => v.Errors);
            }

            // Return to same page with same data
            return(View(projectRole));
        }
        public ActionResult Delete(ProjectRole projectRole)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.ProjectRole))
            {
                return(RedirectToPermissionDenied());
            }

            // Delete the project from the database
            try
            {
                ProjectRoleProcessor.DeleteProjectRole(projectRole.ProjectRoleId);
                TempData[LabelSuccess] = "Deleted role: " + projectRole.Name;
                return(RedirectToIndex());
            }
            catch (Exception e)
            {
                return(RedirectToIndex(e));
            }
        }
        public ActionResult Edit(ProjectRoleGroup projectRoleGroup)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.ProjectRoleGroup))
            {
                return(RedirectToPermissionDenied());
            }

            // Enter main body of the function
            try
            {
                // Check which submit button was pressed
                if (Request.Form["Save"] != null)
                {
                    // Make sure the user is logged in
                    if (!IsUserLoggedIn)
                    {
                        return(RedirectToLogin());
                    }

                    // Make sure the entered data is valid
                    if (ModelState.IsValid)
                    {
                        // Update the project role group within the database
                        try
                        {
                            ProjectRoleGroupProcessor.UpdateProjectRoleGroup(
                                projectRoleGroup.ProjectRoleGroupId,
                                projectRoleGroup.Name);
                            TempData[LabelSuccess] = "Updated group: " + projectRoleGroup.Name;
                            return(RedirectToIndex());
                        }
                        catch (Exception e)
                        {
                            ModelState.AddModelError("", e.Message);
                        }
                    }
                    else
                    {
                        //show error
                        var errors = ModelState.Values.SelectMany(v => v.Errors);
                    }
                }
                else if (Request.Form["Add"] != null)
                {
                    // Add a role link the project role group
                    try
                    {
                        ProjectRoleLinkProcessor.CreateProjectRoleLink(
                            projectRoleGroup.AddLink,
                            projectRoleGroup.ProjectRoleGroupId);
                        ViewBag.Added = "Added project role to group";
                    }
                    catch (Exception e)
                    {
                        ViewBag.AddFail = e.Message;
                    }
                }
                else
                {
                    // Remove a role link the project role group
                    try
                    {
                        const string marker = "Delete.";
                        foreach (string key in Request.Form.AllKeys)
                        {
                            if (key.StartsWith(marker))
                            {
                                ProjectRoleLinkProcessor.DeleteProjectRoleLink(Convert.ToInt32(key.Substring(marker.Length)));
                                ViewBag.Removed = "Removed project role from group";
                                break;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        ViewBag.RemoveFail = e.Message;
                    }
                }

                // Get the project role group data
                var projectRoleGroupModel = ProjectRoleGroupProcessor.GetProjectRoleGroup(projectRoleGroup.ProjectRoleGroupId);
                if (projectRoleGroupModel == null)
                {
                    return(RedirectToIndexIdNotFound(projectRoleGroup.ProjectRoleGroupId));
                }

                // Convert the model data to non-model data
                projectRoleGroup = new ProjectRoleGroup(projectRoleGroupModel);

                // Get list of all project roles
                var projectRoleModels = ProjectRoleProcessor.GetAllProjectRoles();

                // Get the links which are assigned to this group
                projectRoleGroup.Links = GetLinksForGroup(projectRoleGroup.ProjectRoleGroupId, projectRoleModels);

                // Setup the dropdown list with all project roles
                SetupRoleDropDownList(projectRoleModels);

                // Return to same page with same data
                return(View(projectRoleGroup));
            }
            catch (Exception e)
            {
                return(RedirectToIndex(e));
            }
        }