public async Task <ActionResult <Paged <OrderBuyListDto> > > GetPagedOrders( [FromQuery] PagingParams pagingParams, [FromQuery] SortParams sortParams, [FromQuery] OrderBuyQuery query, string filter) { var orders = await _repository.GetPagedOrdersAsync(pagingParams, sortParams, query, filter); return(new Paged <OrderBuyListDto>(orders)); }
public async Task <PagedList <OrderBuyListDto> > GetPagedOrdersAsync( PagingParams pagingParams, SortParams sortParams, OrderBuyQuery queryParams, string filter ) { var source = _context.Set <OrderBuy> () .AsNoTracking() .ProjectToType <OrderBuyListDto> (); switch (sortParams.SortOrder) { case "asc": switch (sortParams.SortColumn) { case "orderNumber": source = source.OrderBy(p => p.OrderNumber); break; case "dateOfIssue": source = source.OrderBy(p => p.DateOfIssue); break; case "timeForPayment": source = source.OrderBy(p => p.TimeForPayment); break; case "supplierName": source = source.OrderBy(p => p.SupplierName); break; case "employeeName": source = source.OrderBy(p => p.EmployeeName); break; case "rating": source = source.OrderBy(p => p.Rating); break; } break; case "desc": switch (sortParams.SortColumn) { case "orderNumber": source = source.OrderByDescending(p => p.OrderNumber); break; case "dateOfIssue": source = source.OrderByDescending(p => p.DateOfIssue); break; case "timeForPayment": source = source.OrderByDescending(p => p.TimeForPayment); break; case "supplierName": source = source.OrderByDescending(p => p.SupplierName); break; case "employeeName": source = source.OrderByDescending(p => p.EmployeeName); break; case "rating": source = source.OrderByDescending(p => p.Rating); break; } break; default: source = source.OrderByDescending(c => c.DateOfIssue); break; } if (queryParams.SupplierId > 0) { source = source.Where(o => o.PersonId == queryParams.SupplierId); } if (queryParams.EmployeeId > 0) { source = source.Where(o => o.EmployeeId == queryParams.EmployeeId); } if (queryParams.FromDate < queryParams.ToDate) { source = source.Where(o => o.DateOfIssue >= queryParams.FromDate && o.DateOfIssue <= queryParams.ToDate); } if (!string.IsNullOrEmpty(filter)) { source = source.Where(p => (p.OrderNumber + p.DateOfIssue + p.SupplierName).ToLower().Contains(filter.ToLower())); } return(await PagedList <OrderBuyListDto> .CreateAsync(source, pagingParams.PageIndex, pagingParams.PageSize)); }