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

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

            // Get all project role groups from the database
            var projectRoleGroupModels = ProjectRoleGroupProcessor.GetAllProjectRoleGroups();

            // Convert the list to the correct type
            List <ProjectRoleGroup> projectRoleGroups = new List <ProjectRoleGroup>();

            foreach (var p in projectRoleGroupModels)
            {
                projectRoleGroups.Add(new ProjectRoleGroup(p));
            }

            // Return the view, with the list of project role groups
            return(View(projectRoleGroups));
        }
        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));
            }
        }
Exemple #3
0
        public ActionResult Edit(int?id)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.Project))
            {
                return(RedirectToPermissionDenied());
            }

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

            // Entry try-catch from here
            // Make sure any errors are displayed
            try
            {
                // Get the project data
                var projectModel = ProjectProcessor.GetProject(projectId);
                if (projectModel == null)
                {
                    return(RedirectToIndexIdNotFound(projectId));
                }

                // Get all project role groups from the database
                var projectRoleGroupModels = ProjectRoleGroupProcessor.GetAllProjectRoleGroups();

                // Get list of available project role groups
                // Store it in a list for a drop-down-list
                ViewBag.RoleGroup = new SelectList(projectRoleGroupModels, "ProjectRoleGroupId", "Name", projectModel.ProjectRoleGroupId);

                // Convert the model data to non-model data
                // Pass the data to the view
                return(View(new Project(projectModel, projectRoleGroupModels)));
            }
            catch (Exception e)
            {
                return(RedirectToIndex(e));
            }
        }
Exemple #4
0
        public ActionResult Edit(Project project)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.Project))
            {
                return(RedirectToPermissionDenied());
            }

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

            // Get list of available project role groups
            // Store it in a list for a drop-down-list
            ViewBag.RoleGroup = new SelectList(ProjectRoleGroupProcessor.GetAllProjectRoleGroups(), "ProjectRoleGroupId", "Name", project.ProjectRoleGroupId);

            // Return to same page with same data
            return(View(project));
        }
Exemple #5
0
        public ActionResult Details(int?id)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.Project))
            {
                return(RedirectToPermissionDenied());
            }

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

            // Entry try-catch from here
            // Make sure any errors are displayed
            try
            {
                // Get the project data
                var projectModel = ProjectProcessor.GetProject(projectId);
                if (projectModel == null)
                {
                    return(RedirectToIndexIdNotFound(projectId));
                }

                // Get name of assigned project role group
                var roleGroup = ProjectRoleGroupProcessor.GetProjectRoleGroup(projectModel.ProjectRoleGroupId);

                //var teams = TeamProcessor.SelectTeamsForUnitOfferingId( projectId );

                // Convert the model data to non-model data
                // Pass the data to the view
                return(View(new Project(projectModel, roleGroup)));
            }
            catch (Exception e)
            {
                return(RedirectToIndex(e));
            }
        }
Exemple #6
0
        public ActionResult Create()
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.Project))
            {
                return(RedirectToPermissionDenied());
            }

            // Get list of available project role groups
            // Store it in a list for a drop-down-list
            ViewBag.RoleGroup = new SelectList(ProjectRoleGroupProcessor.GetAllProjectRoleGroups(), "ProjectRoleGroupId", "Name", null);

            // Go to view
            return(View());
        }
        public ActionResult Create(ProjectRoleGroup projectRoleGroup)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.ProjectRoleGroup))
            {
                return(RedirectToPermissionDenied());
            }

            // Make sure the entered data is valid
            if (ModelState.IsValid)
            {
                // Update the project within the database
                try
                {
                    ProjectRoleGroupProcessor.CreateProjectRoleGroup(projectRoleGroup.Name);
                    TempData[LabelSuccess] = "Created new group: " + projectRoleGroup.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(projectRoleGroup));
        }
        public ActionResult Delete(ProjectRoleGroup projectRoleGroup)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.ProjectRoleGroup))
            {
                return(RedirectToPermissionDenied());
            }

            // Delete the project from the database
            try
            {
                ProjectRoleGroupProcessor.DeleteProjectRoleGroup(projectRoleGroup.ProjectRoleGroupId);
                TempData[LabelSuccess] = "Deleted group: " + projectRoleGroup.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));
            }
        }
Exemple #10
0
        /// <summary>
        /// The main page of the project controller.
        /// Shows a list of all projects in the system.
        /// </summary>
        public ActionResult Index()
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.Project))
            {
                return(RedirectToPermissionDenied());
            }

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

            // Get all projects from the database
            var projectModels = ProjectProcessor.GetAllProjects();

            /*List<TCABS_DataLibrary.Models.ProjectModel> projectModels =
             *  canModify ?
             *  ProjectProcessor.GetAllProjects() :
             *  ProjectOfferingProcessor.GetProjectOfferingsForUserId(CurrentUser.UserId);
             */

            // Get all project role groups from the database
            // Convert the list to a dictionary
            var projectRoleGroupModels = ProjectRoleGroupProcessor.GetAllProjectRoleGroups();
            Dictionary <int, string> projectRoleGroup = null;

            if (projectRoleGroupModels != null)
            {
                projectRoleGroup = new Dictionary <int, string>();
                foreach (var i in projectRoleGroupModels)
                {
                    projectRoleGroup.Add(i.ProjectRoleGroupId, i.Name);
                }
            }

            // Create the project list
            List <Project> projects = new List <Project>();

            if (projectRoleGroup != null)
            {
                foreach (var p in projectModels)
                {
                    projects.Add(new Project(p, projectRoleGroup));
                }
            }
            else
            {
                foreach (var p in projectModels)
                {
                    projects.Add(new Project(p));
                }
            }

            // Make sure the project descriptions are not too long
            const int maxDescriptionLength = 40;

            foreach (var p in projects)
            {
                if ((p.Description != null) && (p.Description.Length > maxDescriptionLength))
                {
                    p.Description = p.Description.Substring(0, maxDescriptionLength - 3) + "...";
                }
            }

            // Return the view, with the list of projects
            return(View(projects));
        }