public List <Project> GetProjects( ) { var data = ProjectProcessor.GetAllProjects( ); Projects = new List <Project>( ); foreach (var row in data) { var project = new Project( ) { ProjectId = row.ProjectId, Name = row.Name, ProjectRoleGroupId = row.ProjectRoleGroupId }; Projects.Add(project); } return(Projects); }
/// <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)); }