public async Task <Result <UpdatePatientDiagnosisResponse> > Handle(UpdatePatientDiagnosisCommand request, CancellationToken cancellationToken) { using (_maternityUnitOfWork) { try { var patientDiagnosis = await _maternityUnitOfWork.Repository <PatientDiagnosis>().Get(x => x.Id == request.DiagnosisId) .SingleOrDefaultAsync(); if (patientDiagnosis == null) { return(Result <UpdatePatientDiagnosisResponse> .Invalid("Patient diagnosis could not be found")); } patientDiagnosis.Update(request.DiagnosisCommand.Diagnosis, request.DiagnosisCommand.ManagementPlan); _maternityUnitOfWork.Repository <PatientDiagnosis>().Update(patientDiagnosis); await _maternityUnitOfWork.SaveAsync(); return(Result <UpdatePatientDiagnosisResponse> .Valid(new UpdatePatientDiagnosisResponse() { MessageResult = "Successfully updated patient diagnosis" })); } catch (Exception e) { Log.Error("Error editing patient diagnosis " + e.Message + " " + e.InnerException); return(Result <UpdatePatientDiagnosisResponse> .Invalid(e.Message)); } } }
public async Task <IActionResult> UpdateDiagnosis([FromBody] UpdatePatientDiagnosisCommand updatePatientDiagnosisCommand) { var response = await _mediator.Send(updatePatientDiagnosisCommand, HttpContext.RequestAborted); if (response.IsValid) { return(Ok(response.Value)); } return(BadRequest(response)); }