public IActionResult GetUnclosedWorkingTime(int userId, int taskId) { if (_repo.GetUser(userId) == null) { return(NotFound()); } if (_repo.GetTask(taskId) == null) { return(NotFound()); } var userWorkTimes = _repo.GetWorkTimesForUser(userId); if (userWorkTimes == null || !userWorkTimes.Any()) { return(NotFound()); } var unfinishedWorkTime = userWorkTimes.FirstOrDefault(o => !EntitiesUtils.IsDateEmpty(o.WorkStartTime) && EntitiesUtils.IsDateEmpty(o.WorkEndTime)); if (unfinishedWorkTime == null) { return(NotFound()); } return(Ok(ModelsMapping.GetWorkTimeDto(unfinishedWorkTime))); }
public IActionResult PatchWorkTime(int userId, int workTimeId, [FromBody] JsonPatchDocument <WorkTimeForPartialUpdateDTO> patchDocument) { if (_repo.GetUser(userId) == null) { return(NotFound()); } var workTimeToUpdate = _repo.GetWorkTime(userId, workTimeId); if (workTimeToUpdate == null) { return(NotFound()); } var workTimeWithUpdatedValues = ModelsMapping.GetWorkTimeForPartialUpdateDto(workTimeToUpdate); patchDocument.ApplyTo(workTimeWithUpdatedValues); if (!ModelState.IsValid) { return(BadRequest()); } ValuesUpdater.ApplyPatchToWorkTimeEntity(workTimeToUpdate, workTimeWithUpdatedValues); _repo.SaveChanges(); return(Ok()); }
public IActionResult GetTeam(int teamId) { var team = _repo.GetTeam(teamId); if (team == null) { return(NotFound()); } return(Ok(ModelsMapping.GetTeamDto(team))); }
public IActionResult GetUser(int userId) { var user = _repo.GetUser(userId); if (user == null) { return(NotFound()); } return(Ok(ModelsMapping.GetUserDto(user))); }
public IActionResult GetVacation(int vacationId) { var vacations = _repo.GetVacation(vacationId); if (vacations == null) { return(NotFound()); } return(Ok(ModelsMapping.GetVacationDto(vacations))); }
public IActionResult GetComment(int commentId) { var comment = _repo.GetComment(commentId); if (comment == null) { return(NotFound()); } return(Ok(ModelsMapping.GetCommentDto(comment))); }
public IActionResult GetPayment(int paymentId) { var payment = _repo.GetPayment(paymentId); if (payment == null) { return(NotFound()); } return(Ok(ModelsMapping.GetPaymentDto(payment))); }
public IActionResult GetManagement(int managementId) { var manager = _repo.GetManager(managementId); if (manager == null) { return(NotFound()); } return(Ok(ModelsMapping.GetManagementDto(manager))); }
public IActionResult GetSickLeave(int sickLeaveId) { var sickLeave = _repo.GetSickLeave(sickLeaveId); if (sickLeave == null) { return(NotFound()); } return(Ok(ModelsMapping.GetSickLeaveDto(sickLeave))); }
public IActionResult PostVacation([FromBody] VacationForCreationDTO vacationFromRequest) { if (vacationFromRequest == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } _repo.AddVacation(ModelsMapping.GetVacationEntity(vacationFromRequest)); return(Ok()); }
public IActionResult PostComment([FromBody] CommentForCreationDto commentFromRequest) { if (commentFromRequest == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } _repo.AddComment(ModelsMapping.GetCommentEntity(commentFromRequest)); return(Ok()); }
public IActionResult PostPayment([FromBody] PaymentForCreationDTO paymentFromRequest) { if (paymentFromRequest == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } _repo.AddPayment(ModelsMapping.GetPaymentEntity(paymentFromRequest)); return(Ok()); }
public IActionResult PostTeam([FromBody] TeamForCreationDTO teamFromRequest) { if (teamFromRequest == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } _repo.AddTeam(ModelsMapping.GetTeamEntity(teamFromRequest)); return(Ok()); }
public IActionResult PostSickLeave([FromBody] SickLeaveForCreationDTO sickLeaveFromRequest) { if (sickLeaveFromRequest == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } _repo.AddSickLeave(ModelsMapping.GetSickLeaveEntity(sickLeaveFromRequest)); return(Ok()); }
public IActionResult PostManagement([FromBody] ManagementForCreationDTO managementFromRequest) { if (managementFromRequest == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } _repo.AddManager(ModelsMapping.GetManagementEntity(managementFromRequest)); return(Ok()); }
public IActionResult AddWorkTime(int userId, [FromBody] WorkTimeForCreationDTO workTimeFromRequest) { if (_repo.GetUser(userId) == null) { return(NotFound("User not found")); } if (!ModelState.IsValid) { return(BadRequest("Invalid model")); } _repo.AddWorkTime(ModelsMapping.GetWorkTimeEntity(workTimeFromRequest)); return(Ok()); }
public IActionResult AddUser([FromBody] UserForCreationDTO userFromRequest) { if (userFromRequest == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } userFromRequest.Password = GetPasswordHash(userFromRequest.Password); _repo.AddUser(ModelsMapping.GetUserEntity(userFromRequest)); return(Ok()); }
public IActionResult GetWorkTimeForUser(int userId, int workTimeId) { if (_repo.GetUser(userId) == null) { return(NotFound()); } var workTime = _repo.GetWorkTime(userId, workTimeId); if (workTime == null) { return(NotFound()); } return(Ok(ModelsMapping.GetWorkTimeDto(workTime))); }
public IActionResult GetSubordinates(int userId) { var users = _repo.GetUsers().Select(ModelsMapping.GetUserDto); if (users == null || !users.Any()) { return(NotFound()); } var currentUser = ModelsMapping.GetUserDto(_repo.GetUser(userId)); if (currentUser == null) { return(BadRequest()); } var subordinatesIdsList = new List <int>(); GetSubordinatesIDs(users, subordinatesIdsList, currentUser); return(Ok(subordinatesIdsList)); }
public IActionResult PatchTask(int taskId, [FromBody] JsonPatchDocument <TaskForPartialUpdateDTO> patchDocument) { var taskToUpdate = _repo.GetTask(taskId); if (taskToUpdate == null) { return(NotFound()); } var taskWithUpdatedValues = ModelsMapping.GetTaskForPartialUpdateDto(taskToUpdate); patchDocument.ApplyTo(taskWithUpdatedValues); if (!ModelState.IsValid) { return(BadRequest()); } ValuesUpdater.ApplyPatchToTaskEntity(taskToUpdate, taskWithUpdatedValues); _repo.SaveChanges(); return(Ok()); }
public IActionResult PatchUser(int userId, [FromBody] JsonPatchDocument <UserForPartialUpdateDTO> patchDocument) { var userToUpdate = _repo.GetUser(userId); if (userToUpdate == null) { return(BadRequest()); } var userWithUpdatedValues = ModelsMapping.GetUserForPartialUpdateDto(userToUpdate); patchDocument.ApplyTo(userWithUpdatedValues); if (!ModelState.IsValid) { return(BadRequest()); } ValuesUpdater.ApplyPatchToUserEntity(userToUpdate, userWithUpdatedValues); _repo.SaveChanges(); return(Ok()); }
public IActionResult PutWorkTime(int userId, int workTimeId, [FromBody] WorkTimeForCreationDTO workTimeFromRequest) { if (workTimeFromRequest == null) { return(BadRequest("task is null")); } if (!ModelState.IsValid) { return(BadRequest("model is not valid")); } var workTimeFromDb = _repo.GetWorkTime(userId, workTimeId); if (workTimeFromDb == null) { return(NotFound()); } ValuesUpdater.UpdateWorkTimeFromDto(workTimeFromDb, workTimeFromRequest); _repo.SaveChanges(); return(Ok(ModelsMapping.GetWorkTimeDto(workTimeFromDb))); }
public IActionResult GetUsers() { return(Ok(_repo.GetUsers().Select(o => ModelsMapping.GetUserDto(o)))); }