public async Task <IActionResult> UpdateHeiEncounter([FromBody] UpdateHeiDeliveryCommand updateHeiDeliveryCommand) { var response = await _mediator.Send(updateHeiDeliveryCommand, Request.HttpContext.RequestAborted); if (response.IsValid) { return(Ok(response.Value)); } return(BadRequest(response)); }
public async Task <Result <UpdateHeiDeliveryResponse> > Handle(UpdateHeiDeliveryCommand request, CancellationToken cancellationToken) { using (_unitOfWork) { try { var heiEncounter = await _unitOfWork.Repository <HEIEncounter>().FindByIdAsync(request.Id); if (heiEncounter != null) { heiEncounter.PlaceOfDeliveryId = request.PlaceOfDeliveryId; heiEncounter.ModeOfDeliveryId = request.ModeOfDeliveryId; heiEncounter.BirthWeight = request.BirthWeight; heiEncounter.ArvProphylaxisId = request.ArvProphylaxisId; heiEncounter.ArvProphylaxisOther = request.ArvProphylaxisOther; heiEncounter.MotherRegisteredId = request.MotherIsRegistered; heiEncounter.MotherPersonId = request.MotherPersonId; heiEncounter.MotherStatusId = request.MotherStatusId; heiEncounter.PrimaryCareGiverID = request.PrimaryCareGiverID; heiEncounter.MotherName = request.MotherName; heiEncounter.MotherCCCNumber = request.MotherCCCNumber; heiEncounter.MotherPMTCTDrugsId = request.MotherPMTCTDrugsId; heiEncounter.MotherPMTCTRegimenId = request.MotherPMTCTRegimenId; heiEncounter.MotherPMTCTRegimenOther = request.MotherPMTCTRegimenOther; heiEncounter.MotherArtInfantEnrolId = request.MotherArtInfantEnrolId; heiEncounter.MotherArtInfantEnrolRegimenId = request.MotherArtInfantEnrolRegimenId; _unitOfWork.Repository <HEIEncounter>().Update(heiEncounter); await _unitOfWork.SaveAsync(); return(Result <UpdateHeiDeliveryResponse> .Valid(new UpdateHeiDeliveryResponse() { Message = "Successfully updated heidelivery" })); } else { return(Result <UpdateHeiDeliveryResponse> .Invalid($"Could not find heiencounter for Id: {request.Id}")); } } catch (Exception e) { Log.Error($"Error updating heidelivery for Id: {request.Id}, Message: {e.Message}"); return(Result <UpdateHeiDeliveryResponse> .Invalid($"Error updating heidelivery for Id: {request.Id}, Message: {e.Message}")); } } }