public async Task <IActionResult> RemoveAssignedHoursToUserForProject([FromBody] HoursRecordForCreation hoursRecord) { User user = await userService.FindUser(hoursRecord.UserId); if (user == null) { ModelState.AddModelError("User", "The user is not found"); } Project project = await projectService.FindProject(hoursRecord.ProjectId); if (project == null) { ModelState.AddModelError("Project", "The project is not found"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { HoursRecord record = await hoursRecordService.RemoveAssignedHoursToUserForProject(hoursRecord); return(Created($"Get/{record.Id}", record)); } catch (Exception xcp) { return(StatusCode(500, xcp.InnerException.Message)); } }
public async Task <IActionResult> AddSpentHoursToUserForProject([FromBody] HoursRecordForCreation hoursRecord) { User user = await userService.FindUser(hoursRecord.UserId); if (user == null) { ModelState.AddModelError("User", "The user is not found"); } Project project = await projectService.FindProject(hoursRecord.ProjectId); if (project == null) { ModelState.AddModelError("Project", "The project is not found"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } int availableHours = await hoursRecordService.CheckAvailableHoursForUserOnProject(user, project); if (availableHours < hoursRecord.Hours) { ModelState.AddModelError("Hours", "There is no enough available hours for the user on the project. Please add him more assigned hours first."); } try { HoursRecord record = await hoursRecordService.AddSpentHoursToUserForProject(hoursRecord); return(Created($"Get/{record.Id}", record)); } catch (Exception xcp) { return(StatusCode(500, xcp.InnerException.Message)); } }