/// <summary> /// The PersonReport displays all the people and the projects they are assigned to, with the associated roles, plus hourly rate. /// </summary> /// <returns>The <see cref="IActionResult"/></returns> public IActionResult PersonReport() { //Read in all the repos for manipulation. var projects = _projectRepo.ReadAll().ToList(); var people = _personRepo.ReadAll().ToList(); var roles = _roleRepo.ReadAll().ToList(); var projectRoles = _projectRoleRepo.ReadAll().ToList(); //Instantiate and declaire ProjectReport VM PersonReportVM model = new PersonReportVM { Projects = _projectRepo.ReadAll().ToList(), Person = _personRepo.ReadAll().ToList(), Roles = _roleRepo.ReadAll().ToList(), ProjectRoles = _projectRoleRepo.ReadAll().ToList(), HourlyTotal = new Dictionary <Project, decimal>(), ListOfProjectsAndPeople = new Dictionary <string, Dictionary <Project, Dictionary <Role, decimal> > >() }; //Loop through each project foreach (var pro in model.Person) { List <int> projectsList = new List <int>(); projectsList = _projectRoleRepo.SelectProjectsAssignedToPeople(pro.Id); Dictionary <Project, Dictionary <Role, decimal> > projectAndRole = new Dictionary <Project, Dictionary <Role, decimal> >(); //Loop through each person foreach (var p in projectsList) { //Get a person var projectAssigned = _projectRepo.Read(p); //Get all the project role by user id and project id List <int> roleIds = _projectRoleRepo.SelectRoleOnProjectByPersonId(p, pro.Id); //Create a list to store roles and hourly rate relationships Dictionary <Role, decimal> assignedRoles = new Dictionary <Role, decimal>(); //Loop through each role foreach (var role in roleIds) { //Get each hourly rate for each project, person, and role. Then add it to a dictionary. var readRoles = _roleRepo.Read(role); var hourly = _projectRoleRepo.HourlyRate(pro.Id, p, role); //If the role does not come back null, add it to the list. if (readRoles != null) { assignedRoles.Add(readRoles, hourly); } } //Check to see if the project has been added if (!projectAndRole.ContainsKey(projectAssigned)) { //Add the user and roles if they have not been added projectAndRole.Add(projectAssigned, assignedRoles); } } //Define full name string fullName = $"{pro.FirstName} {pro.LastName}"; //Check to see if the person key has been added. if (!model.ListOfProjectsAndPeople.ContainsKey(fullName)) { //Put all the dictionaries together. model.ListOfProjectsAndPeople.Add(fullName, projectAndRole); } } return(View(model)); }
/// <summary> /// The ProjectReport gathers a list of the projects, people working on the project, and roles that each person has on each project. (See User Stories #7) /// </summary> /// <returns>The <see cref="IActionResult"/> containing the VM</returns> public IActionResult ProjectReport() { var projects = _projectRepo.ReadAll().ToList(); var people = _personRepo.ReadAll().ToList(); var roles = _roleRepo.ReadAll().ToList(); var projectRoles = _projectRoleRepo.ReadAll().ToList(); //Instantiate and declaire ProjectReport VM ProjectReportVM model = new ProjectReportVM { Projects = _projectRepo.ReadAll().ToList(), Person = _personRepo.ReadAll().ToList(), Roles = _roleRepo.ReadAll().ToList(), ProjectRoles = _projectRoleRepo.ReadAll().ToList(), HourlyTotal = new Dictionary <Project, decimal>(), Test = 0, ListOfProjectsAndPeople = new Dictionary <Project, Dictionary <string, Dictionary <Role, decimal> > >() }; //Loop through each project foreach (var pro in model.Projects) { List <int> persons = new List <int>(); persons = _projectRoleRepo.SelectPeopleOnProject(pro.Id); Dictionary <string, Dictionary <Role, decimal> > personAndRole = new Dictionary <string, Dictionary <Role, decimal> >(); //Loop through each person foreach (var p in persons) { //Get a person var personAssigned = _personRepo.Read(p); //Use string interpulation to create the name var name = $"{personAssigned.FirstName} {personAssigned.LastName}"; //List<string> peopleOnProject = _personRepo.SelectAllPeopleById(p); //Get all the project role by user id and project id List <int> roleIds = _projectRoleRepo.SelectRoleOnProjectByPersonId(pro.Id, p); //Create a list to store roles and hourly rate relationships Dictionary <Role, decimal> assignedRoles = new Dictionary <Role, decimal>(); //Loop through each role foreach (var role in roleIds) { //Get each hourly rate for each project, person, and role. Then add it to a dictionary. var readRoles = _roleRepo.Read(role); var hourly = _projectRoleRepo.HourlyRate(p, pro.Id, role); //If the role isn't null, add it to the list. if (readRoles != null) { assignedRoles.Add(readRoles, hourly); } } //Check to see if the user has been added if (!personAndRole.ContainsKey(name)) { //Add the user and roles if they have not been added personAndRole.Add(name, assignedRoles); } } //Put all the dictionaries together. model.ListOfProjectsAndPeople.Add(pro, personAndRole); } return(View(model)); }