public async Task <IActionResult> UpdatePatient(int patientId, PatientForUpdateDto patient) { var patientFromRepo = await _patientRepository.GetPatientAsync(patientId); if (patientFromRepo == null) { return(NotFound()); } var validationResults = new PatientForUpdateDtoValidator().Validate(patient); validationResults.AddToModelState(ModelState, null); if (!ModelState.IsValid) { return(BadRequest(new ValidationProblemDetails(ModelState))); //return ValidationProblem(); } _mapper.Map(patient, patientFromRepo); _patientRepository.UpdatePatient(patientFromRepo); await _patientRepository.SaveAsync(); return(NoContent()); }
public async Task <IActionResult> UpdatePatient(Guid patientId, PatientForUpdateDto patient) { // add error handling var updateCommand = new PatientForUpdateCommand(patientId, patient); await _mediator.Send(updateCommand); return(NoContent()); }
public async Task <IActionResult> UpdatePatient(int id, PatientForUpdateDto patientForUpdateDto) { var patientFromRepo = await _repo.GetPatient(id); _mapper.Map(patientForUpdateDto, patientFromRepo); if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception($"Les modifications pour le patient {id} n'ont pas pu être sauvegardées"); }
public async Task <IActionResult> updatePatient([FromBody] PatientForUpdateDto patientForUpdate) { try { var patientFromRepo = await _repo.getPatientById(patientForUpdate.Id); _mapper.Map(patientForUpdate, patientFromRepo); await _repo.SaveAll(); } catch (Exception e) { return(BadRequest(e.Message)); } return(StatusCode(200)); }
public async Task <IActionResult> UpdatePatient(int doctorId, int patientId, PatientForUpdateDto patientForUpdateDto) { if (doctorId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized("Пользователь не авторизован")); } var patientFromRepo = await _patientService.GetPatientWithoutCacheAsync(doctorId, patientId); if (patientFromRepo == null) { return(BadRequest("Указаного пациента нет в системе")); } _mapper.Map(patientForUpdateDto, patientFromRepo); if (await _patientService.SaveAllAsync()) { return(Ok(patientFromRepo)); } throw new Exception("Не предвиденая ошибка в ходе обновления пациента, обратитесь к администратору."); }
public UpdatePatientCommand(Guid patient, PatientForUpdateDto patientToUpdate) { PatientId = patient; PatientToUpdate = patientToUpdate; }
public PatientForUpdateCommand(Guid patientId, PatientForUpdateDto patientForUpdateDto) { PatientId = patientId; PatientForUpdateDto = patientForUpdateDto; }