public async Task <Result <AddHeiFeedingCommandResponse> > Handle(AddHeiFeedingCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    HeiFeeding heiFeeding = new HeiFeeding()
                    {
                        PatientId            = request.PatientId,
                        PatientMasterVisitId = request.PatientMasterVisitId,
                        FeedingModeId        = request.FeedingModeId,
                        CreatedBy            = request.UserId,
                        CreateDate           = DateTime.Now,
                        DeleteFlag           = false
                    };

                    await _unitOfWork.Repository <HeiFeeding>().AddAsync(heiFeeding);

                    await _unitOfWork.SaveAsync();

                    return(Result <AddHeiFeedingCommandResponse> .Valid(new AddHeiFeedingCommandResponse()
                    {
                        HeiFeedingId = heiFeeding.Id
                    }));
                }
                catch (Exception e)
                {
                    Log.Error(e.Message + " " + e.InnerException);
                    return(Result <AddHeiFeedingCommandResponse> .Invalid(e.Message));
                }
            }
        }
示例#2
0
        public async Task <Result <HeiFeedingViewModel> > Handle(GetHeiFeedingCommand request, CancellationToken cancellationToken)
        {
            using (_unitOfWork)
            {
                try
                {
                    HeiFeeding result = await _unitOfWork.Repository <HeiFeeding>().Get(x => x.PatientId == request.PatientId).FirstOrDefaultAsync();

                    HeiFeedingViewModel heiFeedingView = new HeiFeedingViewModel();;
                    if (result != null)
                    {
                        heiFeedingView.Id                   = result.Id;
                        heiFeedingView.PatientId            = result.PatientId;
                        heiFeedingView.PatientMasterVisitId = result.PatientMasterVisitId;
                        heiFeedingView.FeedingModeId        = result.FeedingModeId;
                    }

                    return(Result <HeiFeedingViewModel> .Valid(heiFeedingView));
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                    return(Result <HeiFeedingViewModel> .Invalid(e.Message));
                }
            }
        }
示例#3
0
        public async Task <HeiFeeding> GetHeiFeeding(int id)
        {
            try
            {
                HeiFeeding heiFeeding = await _unitOfWork.Repository <HeiFeeding>().FindByIdAsync(id);

                return(heiFeeding);
            }
            catch (Exception e)
            {
                Log.Error(e.Message + " " + e.InnerException);
                throw e;
            }
        }
示例#4
0
        public async Task <HeiFeeding> AddHeiFeeding(HeiFeeding heiFeeding)
        {
            try
            {
                await _unitOfWork.Repository <HeiFeeding>().AddAsync(heiFeeding);

                await _unitOfWork.SaveAsync();

                return(heiFeeding);
            }
            catch (Exception e)
            {
                Log.Error(e.Message + " " + e.InnerException);
                throw;
            }
        }
示例#5
0
        public async Task <HeiFeeding> DeleteHeiFeeding(int id)
        {
            try
            {
                HeiFeeding heiFeeding = _unitOfWork.Repository <HeiFeeding>().FindById(id);
                if (null != heiFeeding)
                {
                    heiFeeding.DeleteFlag = false;
                }
                _unitOfWork.Repository <HeiFeeding>().Update(heiFeeding);
                await _unitOfWork.SaveAsync();

                return(heiFeeding);
            }
            catch (Exception e)
            {
                Log.Error(e.Message + " " + e.InnerException);
                throw;
            }
        }
示例#6
0
        public async Task <HeiFeeding> EditHeiFeeding(HeiFeeding heiFeeding)
        {
            try
            {
                HeiFeeding heiFeedingData =
                    _unitOfWork.Repository <HeiFeeding>().FindById(heiFeeding.Id);
                if (null != heiFeedingData)
                {
                    heiFeedingData.PatientMasterVisitId = heiFeedingData.PatientMasterVisitId;
                    heiFeedingData.FeedingModeId        = heiFeedingData.FeedingModeId;
                }
                _unitOfWork.Repository <HeiFeeding>().Update(heiFeedingData);
                await _unitOfWork.SaveAsync();

                return(heiFeedingData);
            }
            catch (Exception e)
            {
                Log.Error(e.Message + " " + e.InnerException);
                throw;
            }
        }