public async Task <Result <object> > Handle(UpdatePatientVitalCommand request, CancellationToken cancellationToken) { try { var patientVitalInfoToUpdate = _pmtctUnitOfWork.Repository <PatientVital>().Get(x => x.Id == request.PatientVitalInfo.Id) .SingleOrDefault(); if (patientVitalInfoToUpdate == null) { return(Result <object> .Invalid($"Patient vitals information with Id {request.PatientVitalInfo.Id} not found")); } patientVitalInfoToUpdate.UpdateVitalsInfo(request.PatientVitalInfo); _pmtctUnitOfWork.Repository <PatientVital>().Update(patientVitalInfoToUpdate); await _pmtctUnitOfWork.SaveAsync(); return(Result <object> .Valid(new { Message = "Succussfully updated patient vitals information", PatientVitalId = request.PatientVitalInfo.Id })); } catch (Exception ex) { string errorMessage = $"An error occured while updating patient vital information with Id {request.PatientVitalInfo.Id}"; Log.Error(ex, errorMessage); return(Result <object> .Invalid(errorMessage)); } }
public async Task <object> Update([FromBody] UpdatePatientVitalCommand command) { if (!ModelState.IsValid) { return(BadRequest(command)); } var result = await _mediator.Send(command, HttpContext.RequestAborted); if (result.IsValid) { return(Ok(result.Value)); } return(BadRequest(result)); }