public async Task <IActionResult> Post([FromBody] AddPatientIcfCommand addPatientIcfCommand) { var response = await _mediator.Send(addPatientIcfCommand, Request.HttpContext.RequestAborted); if (response.IsValid) { return(Ok(response.Value)); } return(BadRequest(response.Value)); }
public async Task <Result <HeiPatientIcf> > Handle(AddPatientIcfCommand request, CancellationToken cancellationToken) { using (_unitOfWork) { try { HeiPatientIcf heiPatient = _unitOfWork.Repository <HeiPatientIcf>().Get(x => x.PatientId == request.HeiPatientIcf.PatientId && x.PatientMasterVisitId == request.HeiPatientIcf.PatientMasterVisitId && !x.DeleteFlag) .FirstOrDefault(); if (heiPatient == null) { await _unitOfWork.Repository <HeiPatientIcf>().AddAsync(request.HeiPatientIcf); await _unitOfWork.SaveAsync(); } else { heiPatient.ContactWithTb = request.HeiPatientIcf.ContactWithTb; heiPatient.Cough = request.HeiPatientIcf.Cough; heiPatient.EverBeenOnIpt = request.HeiPatientIcf.EverBeenOnIpt; heiPatient.Fever = request.HeiPatientIcf.Fever; heiPatient.OnAntiTbDrugs = request.HeiPatientIcf.OnAntiTbDrugs; heiPatient.ContactWithTb = request.HeiPatientIcf.ContactWithTb; heiPatient.OnIpt = request.HeiPatientIcf.OnIpt; heiPatient.EverBeenOnIpt = request.HeiPatientIcf.EverBeenOnIpt; _unitOfWork.Repository <HeiPatientIcf>().Update(heiPatient); await _unitOfWork.SaveAsync(); } return(Result <HeiPatientIcf> .Valid(request.HeiPatientIcf)); } catch (Exception e) { Log.Error(e.Message + " " + e.InnerException); return(Result <HeiPatientIcf> .Invalid(e.Message)); } } }