Exemplo n.º 1
0
        private async Task <IPagedCollection <InvoiceDetail> > GetInvoicesAsync(GetInvoiceListQuery query)
        {
            var filter = _filterBuilder
                         .WhereBillingAddressLike(query.BillingAddress)
                         .WhereBillingCityEquals(query.BillingCity)
                         .WhereBillingCountryEquals(query.BillingCountry)
                         .WhereBillingPostalCodeEquals(query.BillingPostalCode)
                         .WhereBillingStateEquals(query.BillingState)
                         .WhereCustomerIdEquals(query.CustomerId)
                         .WhereCustomerLike(query.Customer)
                         .WhereDate(query.FromDate, query.ToDate)
                         .WhereTotal(query.FromTotal, query.ToTotal)
                         .Filter;

            var invoicesFromDb = await _context
                                 .Invoices
                                 .AsNoTracking()
                                 .Where(filter)
                                 .Include(invoice => invoice.Customer.SupportRepresentative)
                                 .OrderBy(query.Order, _orderBuilder)
                                 .ToPagedCollectionAsync(query.PageNumber, query.PageSize);

            var invoices = _mapper.Map <IReadOnlyList <InvoiceDetail> >(invoicesFromDb);

            return(new PagedCollection <InvoiceDetail>(
                       invoices,
                       invoicesFromDb.ItemCount,
                       invoicesFromDb.CurrentPageNumber,
                       invoicesFromDb.PageSize));
        }
Exemplo n.º 2
0
        public Task <IPagedCollection <InvoiceDetail> > Handle(GetInvoiceListQuery request, CancellationToken cancellationToken)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            return(GetInvoicesAsync(request));
        }