Esempio n. 1
0
        public async Task <IActionResult> AddFamilyPlanning([FromBody] AddPatientFamilyPlanningMethodCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(command));
            }

            var result = await _mediator.Send(command, HttpContext.RequestAborted);

            if (result.IsValid)
            {
                return(Ok(result.Value));
            }

            return(BadRequest(result));
        }
Esempio n. 2
0
        public async Task <Result <AddFamilyPlaaningMethodResultsResponse> > Handle(AddPatientFamilyPlanningMethodCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var familyPlanningMethod = _mapper.Map <PatientFamilyPlanningMethod>(request);
                await _maternityUnitOfWork.Repository <PatientFamilyPlanningMethod>().AddAsync(familyPlanningMethod);

                await _maternityUnitOfWork.SaveAsync();

                return(Result <AddFamilyPlaaningMethodResultsResponse> .Valid(new AddFamilyPlaaningMethodResultsResponse
                {
                    PatientId = familyPlanningMethod.Id
                }));
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"An error occured while adding patient family planning methods {request.PatientId}");
                return(Result <AddFamilyPlaaningMethodResultsResponse> .Invalid(ex.Message));
            }
        }