public static Vacation GetVacationEntity(VacationForCreationDTO vacationDto) { return(new Vacation() { UserId = vacationDto.UserId, StartTime = vacationDto.StartTime, EndTime = vacationDto.EndTime }); }
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 PutVacation([FromBody] VacationForCreationDTO vacationFromRequest, int vacationId) { if (vacationFromRequest == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest()); } var vacation = _repo.GetVacation(vacationId); ValuesUpdater.UpdateVacationFromDto(vacation, vacationFromRequest); _repo.SaveChanges(); return(Ok()); }
public static void UpdateVacationFromDto(Vacation vacationToUpdate, VacationForCreationDTO vacationWithUpdatedValues) { vacationToUpdate.UserId = vacationWithUpdatedValues.UserId; vacationToUpdate.StartTime = vacationWithUpdatedValues.StartTime; vacationToUpdate.EndTime = vacationWithUpdatedValues.EndTime; }