public async Task <Result <AddPregnancyLogResponse> > Handle(AddPregnancyLogCommand request, CancellationToken cancellationToken) { using (_maternityUnitOfWork) { try { if (request.Id.HasValue && request.Id.Value > 0) { var pregnancy = await _maternityUnitOfWork.Repository <PregnancyLog>().FindByIdAsync(request.Id.Value); pregnancy.LMP = request.LMP; pregnancy.EDD = request.EDD; pregnancy.Outcome = request.Outcome; pregnancy.DateOfOutcome = request.DateOfOutcome; pregnancy.BirthDefects = request.BirthDefects; _maternityUnitOfWork.Repository <PregnancyLog>().Update(pregnancy); await _maternityUnitOfWork.SaveAsync(); } else { PregnancyLog pregnancyLog = new PregnancyLog() { PatientId = request.PatientId, PatientMasterVisitId = request.PatientMasterVisitId, LMP = request.LMP, EDD = request.EDD, Outcome = request.Outcome, DateOfOutcome = request.DateOfOutcome, CreatedBy = request.CreatedBy, CreateDate = DateTime.Now, DeleteFlag = 0, Active = true, BirthDefects = request.BirthDefects }; await _maternityUnitOfWork.Repository <PregnancyLog>().AddAsync(pregnancyLog); await _maternityUnitOfWork.SaveAsync(); } return(Result <AddPregnancyLogResponse> .Valid(new AddPregnancyLogResponse() { Message = "Successfully added pregnancy log" })); } catch (Exception ex) { Log.Error(ex, $"An error occured while trying add patient pregnancy log"); return(Result <AddPregnancyLogResponse> .Invalid($"An error occured while trying add patient pregnancy log")); } } }
public async Task <IActionResult> AddPregnancyOutcome([FromBody] AddPregnancyLogCommand addPregnancyLogCommand) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var response = await _mediator.Send(addPregnancyLogCommand, Request.HttpContext.RequestAborted); if (response.IsValid) { return(Ok(response.Value)); } return(BadRequest(response)); }