Exemplo n.º 1
0
        public Task <FilterResultModel <InvoicePaymentListView> > Handle(GetInvoicePaymentListQuery request, CancellationToken cancellationToken)
        {
            var sortBy        = request.SortBy.Trim() != "" ? request.SortBy : "DateAdded";
            var sortDirection = (request.SortDirection.ToUpper() == "DESCENDING") ? false : true;

            FilterResultModel <InvoicePaymentListView> result = new FilterResultModel <InvoicePaymentListView> ();
            var invoicePayment = _database.InvoicePayments
                                 .Where(i => i.InvoiceNoNavigation != null)
                                 .Select(InvoicePaymentListView.Projection)
                                 .Select(DynamicQueryHelper.GenerateSelectedColumns <InvoicePaymentListView> (request.SelectedColumns))
                                 .AsQueryable();

            if (request.Filter.Count() > 0)
            {
                invoicePayment = invoicePayment
                                 .Where(DynamicQueryHelper
                                        .BuildWhere <InvoicePaymentListView> (request.Filter)).AsQueryable();
            }

            result.Count = invoicePayment.Count();

            var PageSize   = (request.PageSize == 0) ? result.Count : request.PageSize;
            var PageNumber = (request.PageSize == 0) ? 1 : request.PageNumber;

            result.Items = invoicePayment.OrderBy(sortBy, sortDirection)
                           .Skip(PageNumber - 1)
                           .Take(PageSize)
                           .ToList();

            return(Task.FromResult <FilterResultModel <InvoicePaymentListView> > (result));
        }
        public async Task <ActionResult <FilterResultModel <InvoicePaymentListView> > > GetInvoicePaymentsList([FromBody] GetInvoicePaymentListQuery query)
        {
            var result = await _Mediator.Send(query);

            return(StatusCode(200, result));
        }