public static void UpdateWorkTimeFromDto(WorkTime workTimeToUpdate, WorkTimeForCreationDTO workTimeWithUpdatedValues) { workTimeToUpdate.TaskId = workTimeWithUpdatedValues.TaskId; workTimeToUpdate.UserId = workTimeWithUpdatedValues.UserId; workTimeToUpdate.WorkStartTime = workTimeWithUpdatedValues.WorkStartTime; workTimeToUpdate.WorkEndTime = workTimeWithUpdatedValues.WorkEndTime; }
public static WorkTime GetWorkTimeEntity(WorkTimeForCreationDTO workTimeDto) { return(new WorkTime() { WorkStartTime = workTimeDto.WorkStartTime, WorkEndTime = workTimeDto.WorkEndTime, UserId = workTimeDto.UserId, TaskId = workTimeDto.TaskId }); }
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 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))); }