コード例 #1
0
 private static Expression <Func <Transaction, bool> > FilterByDescription(FindTransactions.Request request)
 {
     if (request.Description is { Length : > 0 } description)
     {
         return(t => EF.Functions.Like(t.Description, $"%{description}%"));
     }
     return(t => true);
 }
コード例 #2
0
 private static Expression <Func <Transaction, bool> > FilterByCategory(FindTransactions.Request request)
 {
     if (request.CategoryId != default)
     {
         return(t => t.CategoryId == request.CategoryId && t.TransactionType == request.TransactionType);
     }
     return(t => true);
 }
コード例 #3
0
        public Task <List <Transaction> > FindAsync(FindTransactions.Request request)
        {
            var transactions = _context
                               .Transactions
                               .Where(t => !t.InActive)
                               .Where(FilterByDate(request))
                               .Where(FilterByDescription(request))
                               .Where(FilterByCategory(request))
                               .Include(t => t.Category)
                               .ToListAsync();

            return(transactions);
        }
コード例 #4
0
        private static Expression <Func <Transaction, bool> > FilterByDate(FindTransactions.Request request)
        {
            if (request.From != default && request.To == default)
            {
                return((t) => t.Username == request.Username && t.DateTime >= request.From);
            }

            if (request.From == default && request.To != default)
            {
                return((t) => t.Username == request.Username && t.DateTime <= request.To);
            }

            if (request.From != default && request.To != default)
            {
                return((t) => t.Username == request.Username && t.DateTime >= request.From && t.DateTime <= request.To);
            }

            return((t) => t.Username == request.Username);
        }
コード例 #5
0
 public async Task <IActionResult> FindAsync([FromQuery] FindTransactions.Request request, CancellationToken cancellationToken)
 {
     return(Ok(await _mediator.Send(request, cancellationToken)));
 }
コード例 #6
0
 private static Expression <Func <Transaction, bool> > FilterByUsername(FindTransactions.Request request)
 {
     return(t => t.Username == request.Username);
 }