Exemple #1
0
        public async Task <Result <PatientChronicIllness> > Handle(EditPatientChronicIllnessCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    PatientChronicIllness patientChronicIllness = _unitOfWork.Repository <PatientChronicIllness>()
                                                                  .Get(x => x.Id == request.PatientChronicIllness.Id &&
                                                                       x.PatientId == request.PatientChronicIllness.PatientId).FirstOrDefault();
                    if (patientChronicIllness != null)
                    {
                        patientChronicIllness.ChronicIllness = request.PatientChronicIllness.ChronicIllness;
                        patientChronicIllness.Dose           = request.PatientChronicIllness.Dose;
                        patientChronicIllness.Duration       = request.PatientChronicIllness.Duration;
                        patientChronicIllness.OnsetDate      = request.PatientChronicIllness.OnsetDate;
                        patientChronicIllness.Treatment      = request.PatientChronicIllness.Treatment;
                    }

                    _unitOfWork.Repository <PatientChronicIllness>().Update(patientChronicIllness);
                    await _unitOfWork.SaveAsync();

                    return(Result <PatientChronicIllness> .Valid(request.PatientChronicIllness));
                }
                catch (Exception e)
                {
                    Log.Error(e.Message + " " + e.InnerException);
                    return(Result <PatientChronicIllness> .Invalid(e.Message));
                }
            }
        }
Exemple #2
0
        public async Task <IActionResult> Put([FromBody] EditPatientChronicIllnessCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(command));
            }
            var response = await _mediator.Send(command, HttpContext.RequestAborted);

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

            return(BadRequest(response));
        }