public async Task <Result <AddHeiFeedingCommandResponse> > Handle(AddHeiFeedingCommand request, CancellationToken cancellationToken) { using (_unitOfWork) { try { HeiFeeding heiFeeding = new HeiFeeding() { PatientId = request.PatientId, PatientMasterVisitId = request.PatientMasterVisitId, FeedingModeId = request.FeedingModeId, CreatedBy = request.UserId, CreateDate = DateTime.Now, DeleteFlag = false }; await _unitOfWork.Repository <HeiFeeding>().AddAsync(heiFeeding); await _unitOfWork.SaveAsync(); return(Result <AddHeiFeedingCommandResponse> .Valid(new AddHeiFeedingCommandResponse() { HeiFeedingId = heiFeeding.Id })); } catch (Exception e) { Log.Error(e.Message + " " + e.InnerException); return(Result <AddHeiFeedingCommandResponse> .Invalid(e.Message)); } } }
public async Task <IActionResult> Post([FromBody] AddHeiFeedingCommand heiFeedingCommand) { var response = await _mediator.Send(new AddHeiFeedingCommand { PatientMasterVisitId = heiFeedingCommand.PatientMasterVisitId, PatientId = heiFeedingCommand.PatientId, FeedingModeId = heiFeedingCommand.FeedingModeId }, Request.HttpContext.RequestAborted); if (response.IsValid) { return(Ok(response.Value)); } return(BadRequest(response)); }