private void UpdateProdLabors(string[] selectedProdLabors, ProductionPlan productionPlanToUpdate) { if (selectedProdLabors == null) { productionPlanToUpdate.ProdPlanLabours = new List <ProdPlanLabour>(); return; } var selectedProdLaborsHS = new HashSet <string>(selectedProdLabors); var prodLabors = new HashSet <int> (productionPlanToUpdate.ProdPlanLabours.Select(p => p.LabourReqID)); foreach (var l in _context.LabourRequirements) { if (selectedProdLaborsHS.Contains(l.ID.ToString())) { if (!prodLabors.Contains(l.ID)) { productionPlanToUpdate.ProdPlanLabours.Add(new ProdPlanLabour { LabourReqID = l.ID, ProdPlanID = productionPlanToUpdate.ID }); } } else { if (prodLabors.Contains(l.ID)) { ProdPlanLabour labourToRemove = productionPlanToUpdate.ProdPlanLabours.SingleOrDefault(p => p.LabourReqID == l.ID); _context.Remove(labourToRemove); } } } }
private void UpdateProjectEmployees(string[] selectedOptions, Project projectToUpdate) { if (selectedOptions == null) { projectToUpdate.ProjectEmployees = new List <ProjectEmployee>(); return; } var selectedOptionsHS = new HashSet <string>(selectedOptions); var projEmployees = new HashSet <int>(projectToUpdate.ProjectEmployees.Select(b => b.EmployeeID)); foreach (var s in _context.Employees) { if (selectedOptionsHS.Contains(s.ID.ToString())) { if (!projEmployees.Contains(s.ID)) { projectToUpdate.ProjectEmployees.Add(new ProjectEmployee { EmployeeID = s.ID, ProjectID = projectToUpdate.ID }); } } else { if (projEmployees.Contains(s.ID)) { ProjectEmployee employeeToRemove = projectToUpdate.ProjectEmployees.SingleOrDefault(d => d.EmployeeID == s.ID); _context.Remove(employeeToRemove); } } } }
private void UpdateEmpFullNametoTeam(string[] selectedOptions, Team teamToUpdate) { if (selectedOptions == null) { teamToUpdate.TeamEmployees = new List <TeamEmployee>(); return; } var selectedOptionsHS = new HashSet <string>(selectedOptions); var teamEmps = new HashSet <int>(teamToUpdate.TeamEmployees.Select(e => e.EmployeeID)); foreach (var s in _context.Employees) { if (selectedOptionsHS.Contains(s.ID.ToString())) { if (!teamEmps.Contains(s.ID)) { teamToUpdate.TeamEmployees.Add(new TeamEmployee { EmployeeID = s.ID, TeamID = teamToUpdate.ID }); } } else { if (teamEmps.Contains(s.ID)) { TeamEmployee specToRemove = teamToUpdate.TeamEmployees.SingleOrDefault(d => d.EmployeeID == s.ID); _context.Remove(specToRemove); } } } }
private void UpdateEmployeeTypes(string[] selectedOptions, string[] selectedQuantity, Project projectToUpdate) { if (selectedOptions == null) { projectToUpdate.LabourSummaries = new List <LabourSummary>(); return; } int ctr = 0; var selectedEmployeeTypeHS = new HashSet <string>(selectedOptions); var selectedEmployeeTypeHoursHS = new HashSet <string>(selectedQuantity); var LabourSummariesHS = new HashSet <int> (projectToUpdate.LabourSummaries.Select(c => c.EmployeeTypeID)); foreach (var employeeType in _context.EmployeeTypes) { if (selectedEmployeeTypeHS.Contains(employeeType.ID.ToString())) { if (LabourSummariesHS.Contains(employeeType.ID)) { LabourSummary employeeTypeToRemove = projectToUpdate.LabourSummaries.SingleOrDefault(c => c.EmployeeTypeID == employeeType.ID); _context.Remove(employeeTypeToRemove); projectToUpdate.LabourSummaries.Add(new LabourSummary { ProjectID = projectToUpdate.ID, EmployeeTypeID = employeeType.ID, Hours = int.Parse(selectedQuantity[ctr]) }); } if (!LabourSummariesHS.Contains(employeeType.ID)) { projectToUpdate.LabourSummaries.Add(new LabourSummary { ProjectID = projectToUpdate.ID, EmployeeTypeID = employeeType.ID, Hours = int.Parse(selectedQuantity[ctr]) }); } ctr++; } else { if (LabourSummariesHS.Contains(employeeType.ID)) { LabourSummary employeeTypeToRemove = projectToUpdate.LabourSummaries.SingleOrDefault(c => c.EmployeeTypeID == employeeType.ID); _context.Remove(employeeTypeToRemove); } } } }
private void UpdateProjectLabours(string[] selectedLabors, Project projectToUpdate) { if (selectedLabors == null) { projectToUpdate.ProjectLabours = new List <ProjectLabour>(); return; } var selectedLaborsHS = new HashSet <string>(selectedLabors); var projLabors = new HashSet <int?> (projectToUpdate.ProjectLabours.Select(p => p.LabourReqID)); foreach (var l in _context.LabourRequirements .Include(l => l.Task) .Include(l => l.Team)) { if (selectedLaborsHS.Contains(l.ID.ToString())) { if (!projLabors.Contains(l.ID)) { projectToUpdate.ProjectLabours.Add(new ProjectLabour { LabourReqID = l.ID, ProjectID = projectToUpdate.ID }); } } else { if (projLabors.Contains(l.ID)) { ProjectLabour labourToRemove = projectToUpdate.ProjectLabours.SingleOrDefault(p => p.LabourReqID == l.ID); _context.Remove(labourToRemove); } } } }