public async Task <IActionResult> PostPatientScreenings([FromBody] AddPatientScreeningsCommand addPatientScreeningsCommand) { if (!ModelState.IsValid) { return(BadRequest(addPatientScreeningsCommand)); } var result = await _mediator.Send(addPatientScreeningsCommand, HttpContext.RequestAborted); if (result.IsValid) { return(Ok(result.Value)); } return(BadRequest(result)); }
public async Task <Result <PatientScreeningsResponse> > Handle(AddPatientScreeningsCommand request, CancellationToken cancellationToken) { using (_maternityUnitOfWork) { try { if (request.Screenings.Any()) { List <PatientScreening> clientScreenings = new List <PatientScreening>(); request.Screenings.ForEach(x => clientScreenings.Add(new PatientScreening { PatientId = request.PatientId, PatientMasterVisitId = request.PatientMasterVisitId, DeleteFlag = false, CreateDate = DateTime.Now, CreatedBy = request.CreatedBy, Comment = (x.Comment == null) ? "" : x.Comment, Active = false, ScreeningCategoryId = x.ScreeningCategoryId, ScreeningDate = request.VisitDate, ScreeningDone = true, ScreeningTypeId = x.ScreeningTypeId, ScreeningValueId = x.ScreeningValueId, VisitDate = request.VisitDate })); await _maternityUnitOfWork.Repository <PatientScreening>().AddRangeAsync(clientScreenings); await _maternityUnitOfWork.SaveAsync(); } return(Result <PatientScreeningsResponse> .Valid(new PatientScreeningsResponse() { Message = "Successfully added patient screening" })); } catch (Exception e) { Log.Error($""); return(Result <PatientScreeningsResponse> .Invalid($"")); } } }