コード例 #1
0
        public async Task <Result <AddWHOStageCommandResponse> > Handle(AddWHOStageCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    PatientWHOStage patientWHOStage = new PatientWHOStage()
                    {
                        PatientId            = request.PatientWHOStage.PatientId,
                        PatientMasterVisitId = request.PatientWHOStage.PatientMasterVisitId,
                        WHOStage             = request.PatientWHOStage.WHOStage
                    };

                    await _unitOfWork.Repository <PatientWHOStage>().AddAsync(patientWHOStage);

                    await _unitOfWork.SaveAsync();

                    _unitOfWork.Dispose();

                    return(Result <AddWHOStageCommandResponse> .Valid(new AddWHOStageCommandResponse()
                    {
                        WhoStageId = patientWHOStage.Id
                    }));
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                    return(Result <AddWHOStageCommandResponse> .Invalid(e.Message));
                }
            }
        }
コード例 #2
0
        public async Task <Result <EditWHOStageCommandResponse> > Handle(EditWHOStageCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    PatientWHOStage patientWHOStage = await _unitOfWork.Repository <PatientWHOStage>().FindAsync(x => x.PatientId == request.PatientWHOStage.PatientId && x.Id == request.PatientWHOStage.Id);

                    if (patientWHOStage != null)
                    {
                        patientWHOStage.WHOStage = request.PatientWHOStage.WHOStage;
                    }
                    int result = await _unitOfWork.SaveChangesAsync();

                    _unitOfWork.Dispose();
                    return(Result <EditWHOStageCommandResponse> .Valid(new EditWHOStageCommandResponse()
                    {
                        WHOStageId = result
                    }));
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                    return(Result <EditWHOStageCommandResponse> .Invalid(e.Message));
                }
            }
        }