public async Task <Result <AddPatientDeliveryInfoResponse> > Handle(AddMaternalPatientDeliveryInfoCommand request, CancellationToken cancellationToken) { try { var patientDelivery = _mapper.Map <PatientDeliveryInformation>(request); await _maternityUnitOfWork.Repository <PatientDeliveryInformation>().AddAsync(patientDelivery); await _maternityUnitOfWork.SaveAsync(); return(Result <AddPatientDeliveryInfoResponse> .Valid(new AddPatientDeliveryInfoResponse { PatientDeliveryId = patientDelivery.Id, PatientMasterVisitId = request.PatientMasterVisitId, PregnancyId = request.PregnancyId })); } catch (Exception ex) { string error = $"An error occured while capturing patient delivery information for Master visit {request.PatientMasterVisitId}"; _logger.Error(ex, error); return(Result <AddPatientDeliveryInfoResponse> .Invalid(error)); } }
public async Task <object> AddPatientDeliveryInfo([FromBody] AddMaternalPatientDeliveryInfoCommand command) { if (!ModelState.IsValid) { return(BadRequest(command)); } var response = await _mediator.Send(command, HttpContext.RequestAborted); if (response.IsValid) { return(Ok(response.Value)); } return(BadRequest(response)); }