public async Task <Result <int> > Handle(UpdateLineItemCommand command, CancellationToken cancellationToken) { var lineItem = await _lineItemRepository.GetByIdAsync(command.Id); if (lineItem == null) { return(Result <int> .Fail($"LineItem Not Found.")); } else { lineItem.ClaimId = command.ClaimId; lineItem.CategoryId = command.CategoryId; lineItem.Payee = command.Payee; lineItem.Date = command.Date; lineItem.Description = command.Description; lineItem.Amount = command.Amount; lineItem.CurrencyId = command.CurrencyId; lineItem.USDAmount = command.USDAmount; await _lineItemRepository.UpdateAsync(lineItem); await _unitOfWork.Commit(cancellationToken); return(Result <int> .Success(lineItem.Id)); } }
public async Task <Result <GetLineItemByIdResponse> > Handle(GetLineItemByIdQuery query, CancellationToken cancellationToken) { var lineItem = await _lineItem.GetByIdAsync(query.Id); var mappedLineItem = _mapper.Map <GetLineItemByIdResponse>(lineItem); return(Result <GetLineItemByIdResponse> .Success(mappedLineItem)); }
public async Task <Result <int> > Handle(DeleteLineItemCommand command, CancellationToken cancellationToken) { var lineItem = await _lineItemRepository.GetByIdAsync(command.Id); await _lineItemRepository.DeleteAsync(lineItem); await _unitOfWork.Commit(cancellationToken); return(Result <int> .Success(lineItem.Id)); }
public async Task<LineItem> GetByIdAsync(int lineItemId) { string cacheKey = LineItemCacheKeys.GetKey(lineItemId); var lineItem = await _distributedCache.GetAsync<LineItem>(cacheKey); if (lineItem == null) { lineItem = await _lineItemRepository.GetByIdAsync(lineItemId); Throw.Exception.IfNull(lineItem, "LineItem", "No LineItem Found"); await _distributedCache.SetAsync(cacheKey, lineItem); } return lineItem; }
public async Task <Result <int> > Handle(UpdateLineItemImageCommand command, CancellationToken cancellationToken) { var lineItem = await _lineItemRepository.GetByIdAsync(command.Id); if (lineItem == null) { throw new ApiException($"LineItem Not Found."); } else { lineItem.Receipt = command.Receipt; await _lineItemRepository.UpdateAsync(lineItem); await _unitOfWork.Commit(cancellationToken); return(Result <int> .Success(lineItem.Id)); } }