public async Task <FilterResultModel <PartnerViewModel> > Handle(GetPartnersListQuery request, CancellationToken cancellationToken)
        {
            var sortBy        = request.SortBy.Trim() != "" ? request.SortBy : "PartnerName";
            var sortDirection = (request.SortDirection.ToUpper() == "DESCENDING") ? true : false;

            FilterResultModel <PartnerViewModel> result = new FilterResultModel <PartnerViewModel> ();
            var customer = _database.VehicleOwner
                           .Select(PartnerViewModel.Projection)
                           .Select(DynamicQueryHelper.GenerateSelectedColumns <PartnerViewModel> (request.SelectedColumns))
                           .AsQueryable();

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

            result.Count = customer.Count();

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

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

            return(result);
        }
示例#2
0
        public async Task <ActionResult <FilterResultModel <PartnerViewModel> > > GetPartnersList([FromBody] GetPartnersListQuery query)
        {
            var owner = await _Mediator.Send(query);

            return(Ok(owner));
        }