public async Task <IActionResult> SearchPagination([FromQuery] OrderDto_Filter filter) { return(Ok(await _orderService.SearchPagination(filter))); }
public async Task <ServiceResponseWithPagination <List <OrderDto_ToReturn> > > SearchPagination(OrderDto_Filter filter) { var order = _dbContext.Orders.Include(x => x.OrderItems).ThenInclude(x => x.Products).AsQueryable(); order = order.Where(x => x.IsActive == filter.IsActive); // 2. Order => Order by if (!string.IsNullOrWhiteSpace(filter.OrderingField)) { try { order = order.OrderBy($"{filter.OrderingField} {(filter.AscendingOrder ? "ascending" : "descending")}"); } catch { return(ResponseResultWithPagination.Failure <List <OrderDto_ToReturn> >($"Could not order by field: {filter.OrderingField}")); } } var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(order, filter.RecordsPerPage, filter.Page); // var custom = await cus.Paginate(filter).ToListAsync(); var result = _mapper.Map <List <OrderDto_ToReturn> >(await order.Paginate(filter).ToListAsync()); return(ResponseResultWithPagination.Success(result, paginationResult)); }