public async Task <Result <int> > Handle(UpdateClaimCommand command, CancellationToken cancellationToken)
            {
                var claim = await _claimRepository.GetByIdAsync(command.Id);

                if (claim == null)
                {
                    throw new NotFoundException(nameof(claim), command.Id);
                }

                if (claim == null)
                {
                    return(Result <int> .Fail($"Claim Not Found."));
                }
                else
                {
                    claim.Title         = command.Title;
                    claim.Requester     = command.Requester;
                    claim.Approver      = command.Approver;
                    claim.SubmitDate    = command.SubmitDate;
                    claim.ApprovalDate  = command.ApprovalDate;
                    claim.ProcessedDate = command.ProcessedDate;
                    claim.TotalAmount   = command.TotalAmount;
                    claim.Status        = command.Status;
                    //claim.Status = (Status)Enum.Parse(typeof(Status), command.Status);
                    claim.RequesterComments = command.RequesterComments;
                    claim.ApproverComments  = command.ApproverComments;
                    claim.FinanceComments   = command.FinanceComments;

                    await _claimRepository.UpdateAsync(claim);

                    await _unitOfWork.Commit(cancellationToken);

                    return(Result <int> .Success(claim.Id));
                }
            }
            public async Task <Result <Claim> > Handle(GetClaimByIdQueryToClaim query, CancellationToken cancellationToken)
            {
                var claim = await _claim.GetByIdAsync(query.Id);

                var mappedClaim = _mapper.Map <GetClaimByIdResponse>(claim);

                return(Result <Claim> .Success(claim));
            }
            public async Task <Result <int> > Handle(DeleteClaimCommand command, CancellationToken cancellationToken)
            {
                var product = await _claimRepository.GetByIdAsync(command.Id);

                await _claimRepository.DeleteAsync(product);

                await _unitOfWork.Commit(cancellationToken);

                return(Result <int> .Success(product.Id));
            }
        public async Task <Claim> GetByIdAsync(int claimId)
        {
            string cacheKey = ClaimCacheKeys.GetKey(claimId);
            var    claim    = await _distributedCache.GetAsync <Claim>(cacheKey);

            if (claim == null)
            {
                claim = await _claimRepository.GetByIdAsync(claimId);

                Throw.Exception.IfNull(claim, "Claim", "No Claim Found");
                await _distributedCache.SetAsync(cacheKey, claim);
            }
            return(claim);
        }
Ejemplo n.º 5
0
 public async Task <ClaimBase> GetByIdAsync(int id)
 {
     return(await _claimRepository.GetByIdAsync(id));
 }