public async Task <Result <AddPatientAllergiesResponse> > Handle(AddAllergiesCommand request, CancellationToken cancellationToken) { try { if (request.PatientAllergies.Any()) { List <PatientAllergy> patientAllergies = _mapper.Map <List <PatientAllergy> >(request.PatientAllergies); await _commontUnitOfWork.Repository <PatientAllergy>().AddRangeAsync(patientAllergies); await _commontUnitOfWork.SaveAsync(); } return(Result <AddPatientAllergiesResponse> .Valid(new AddPatientAllergiesResponse { Message = "Successfully added patient allergies" })); } catch (Exception ex) { Log.Error(ex, $"An error occured while adding patient Allergy information"); return(Result <AddPatientAllergiesResponse> .Invalid(ex.Message)); } }
public async Task <IActionResult> AddAllergy([FromBody] AddAllergiesCommand addAllergyCommand) { var response = await _mediator.Send(addAllergyCommand, Request.HttpContext.RequestAborted); if (response.IsValid) { return(Ok(response.Value)); } return(BadRequest(response)); }