Example #1
0
        public async Task <IActionResult> UpdateFamilyPlanningMethod([FromBody] UpdatePatientFamilyPlanningMethodCommand updatePatientFamilyPlanningMethodCommand)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(updatePatientFamilyPlanningMethodCommand));
            }
            var response = await _mediator.Send(updatePatientFamilyPlanningMethodCommand,
                                                Request.HttpContext.RequestAborted);

            if (response.IsValid)
            {
                return(Ok(response.Value));
            }
            return(BadRequest(response));
        }
Example #2
0
        public async Task <Result <UpdatePatientFamilyPlanningMethodResponse> > Handle(UpdatePatientFamilyPlanningMethodCommand request, CancellationToken cancellationToken)
        {
            using (_maternityUnitOfWork)
            {
                try
                {
                    var familyPlanningMethod = await _maternityUnitOfWork.Repository <PatientFamilyPlanningMethod>()
                                               .FindByIdAsync(request.Id);

                    if (familyPlanningMethod != null)
                    {
                        familyPlanningMethod.FPMethodId = request.FPMethodId;

                        _maternityUnitOfWork.Repository <PatientFamilyPlanningMethod>().Update(familyPlanningMethod);
                        await _maternityUnitOfWork.SaveAsync();
                    }
                    else
                    {
                        PatientFamilyPlanningMethod patientFamilyPlanningMethod =
                            new PatientFamilyPlanningMethod(request.PatientId, request.PatientFPId, request.FPMethodId,
                                                            request.UserId);

                        await _maternityUnitOfWork.Repository <PatientFamilyPlanningMethod>()
                        .AddAsync(patientFamilyPlanningMethod);

                        await _maternityUnitOfWork.SaveAsync();
                    }

                    return(Result <UpdatePatientFamilyPlanningMethodResponse> .Valid(new UpdatePatientFamilyPlanningMethodResponse()
                    {
                        Message = $"Successfully updated patientfamilyplanningmethod with id: {request.Id}"
                    }));
                }
                catch (Exception e)
                {
                    Log.Error($"Error updating family planning method with id: {request.Id}");
                    return(Result <UpdatePatientFamilyPlanningMethodResponse> .Invalid($"Error updating family planning method with id: {request.Id}"));
                }
            }
        }