public async Task <IActionResult> ReferPatient([FromBody] ReferPatientCommand command) { var response = await _mediator.Send(command, Request.HttpContext.RequestAborted); if (response.IsValid) { return(Ok(response.Value)); } return(BadRequest(response)); }
public async Task <Result <ReferPatientResponse> > Handle(ReferPatientCommand request, CancellationToken cancellationToken) { try { var referral = new Referral { PersonId = request.PersonId, ReferralDate = DateTime.Now, FromFacility = request.FromFacilityId, FromServicePoint = request.ServiceAreaId, ToServicePoint = request.ServiceAreaId, ToFacility = request.ReferredTo, ReferralReason = request.ReferralReason, ReferredBy = request.UserId, CreatedBy = request.UserId, ExpectedDate = request.DateToBeEnrolled, CreateDate = DateTime.Now, DeleteFlag = false }; await _hTSUnitOfWork.Repository <Referral>().AddAsync(referral); await _hTSUnitOfWork.SaveAsync(); List <Core.Model.Tracing> tracings = new List <Core.Model.Tracing>(); request.Tracing.ForEach(t => tracings.Add(new Core.Model.Tracing { PersonID = request.PersonId, TracingType = t.TracingType, DateTracingDone = t.TracingDate, Mode = t.Mode, Outcome = t.Outcome, Remarks = null, CreatedBy = request.UserId, DeleteFlag = false, CreateDate = DateTime.Now })); await _hTSUnitOfWork.Repository <Core.Model.Tracing>().AddRangeAsync(tracings); await _hTSUnitOfWork.SaveAsync(); _hTSUnitOfWork.Dispose(); return(Result <ReferPatientResponse> .Valid(new ReferPatientResponse { ReferralId = referral.Id })); } catch (Exception ex) { return(Result <ReferPatientResponse> .Invalid(ex.Message)); } }