public ActionResult <AppointmentReadDto> UpdateAppointment(int id, [FromBody] AppointmentUpdateDto updateDto) { var modelFromRepo = _repository.GetAppointmentById(id); if (modelFromRepo == null) { return(NotFound()); } _mapper.Map(updateDto, modelFromRepo); _repository.UpdateAppointment(modelFromRepo); return(NoContent()); }
public async Task <IActionResult> Update([FromBody] AppointmentUpdateDto appointmentDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var model = await ModelsRepository.FindByIdAsync(appointmentDto.Id); if (model == null) { throw new ModelNotFoundException(nameof(AppointmentModel.Id), appointmentDto.Id, typeof(AppointmentModel)); } model.WhenOccured = appointmentDto.WhenOccured; if (!TryValidateModel(model)) { return(BadRequest(ModelState)); } await ModelsRepository.UpdateAsync(model); return(Ok()); }