public ProjectIDEmployee AddEmployeeToProject(ProjectIDEmployee projectIDEmployee) { Project project = context.Projects.Include(p => p.EmployeeProjectHourPerWeeks).Where(p => p.Id == projectIDEmployee.ProjectId).FirstOrDefault(); Employee employee = employeeServices.FindEmployeeById(projectIDEmployee.EmployeeId); List <HourPerWeek> hours = (List <HourPerWeek>)GetEmployeesHoursPerWeek(projectIDEmployee.EmployeeId, projectIDEmployee.ProjectId); int current = 0; foreach (var item in hours) { current += item.Hour; } project.CurrentHours = current; EmployeeProjectHourPerWeeks employeeProjectHourPerWeeks = new EmployeeProjectHourPerWeeks(); employeeProjectHourPerWeeks.Employee = employee; employeeProjectHourPerWeeks.Project = project; employeeProjectHourPerWeeks.HoursPerWeeks = hours; employee.EmployeeProjectHourPerWeeks.Add(employeeProjectHourPerWeeks); project.EmployeeProjectHourPerWeeks.Add(employeeProjectHourPerWeeks); context.SaveChanges(); context.SaveChanges(); return(projectIDEmployee); }
public ProjectIDEmployee AddEmployeeToProject([FromBody] ProjectIDEmployee projectIDEmployee) { return(projectServices.AddEmployeeToProject(projectIDEmployee)); }