//ALL METHODS WITH VIEWS** // GET: Managers public async Task <IActionResult> Index() { ManagerIndexVM indexVM = new ManagerIndexVM(); var manager = await GetCurrentUser(); indexVM.Manager = manager; indexVM.Employees = await _repo.Employee.GetAllEmployees(indexVM.Manager.ManagerId); indexVM.Projects = await _repo.Project.GetAllProjects(manager.ManagerId); await SetEmployeesAssignedTasks(indexVM.Employees); GetQualityOfWork(indexVM.Employees); await GetJobsForEachProject(indexVM); GetPercentageOfTasksDone(indexVM); return(View(indexVM)); }
public async Task GetJobsForEachProject(ManagerIndexVM indexVM) { foreach (Project project in indexVM.Projects) { project.Jobs = await _repo.Job.GetAllJobs(project.ProjectId); //All jobs so that the jobs can have an employee assigned to it in the index view if (indexVM.Jobs == null) { indexVM.Jobs = project.Jobs; } else { indexVM.Jobs = indexVM.Jobs.Concat(project.Jobs).ToList(); } project.Jobs = project.Jobs.OrderBy(j => j.Deadline).ToList(); } }
public void GetPercentageOfTasksDone(ManagerIndexVM indexVM) { foreach (Project project in indexVM.Projects) { double jobsComplete = 0; double totalJobs = project.Jobs.Count(); if (totalJobs == 0) { continue; } foreach (Job job in project.Jobs) { if (job.IsComplete) { jobsComplete++; } } double result = (jobsComplete / totalJobs) * 100; project.PercentComplete = (int)Math.Round(result); } }