public async Task <ServiceResponse <List <OrderDTO_ToReturn> > > SearchOrderPaginate(OrderDTO_Filter filter) { var queryable = _dbContext.Orders.AsQueryable(); //filter if (!String.IsNullOrWhiteSpace(filter.PaymentType)) { queryable = queryable.Where(x => (x.PaymentType).Contains(filter.PaymentType)); } if (filter.MinPrice != 0) { queryable = queryable.Where(x => x.TotalPrice >= filter.MinPrice); } //Order By if (!string.IsNullOrWhiteSpace(filter.OrderingField)) { try { queryable = queryable.OrderBy($"{filter.OrderingField} {(filter.AscendingOrder ? "ascending" : "descending")}"); } catch { return(ResponseResultWithPagination.Failure <List <OrderDTO_ToReturn> >($"Could not order by field: {filter.OrderingField}")); } } //Add Paginate var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(queryable, filter.RecordsPerPage, filter.Page); //Excute query var order = await queryable.Paginate(filter).ToListAsync(); var result = _mapper.Map <List <OrderDTO_ToReturn> >(order); return(ResponseResultWithPagination.Success(result, paginationResult)); }
public async Task <IActionResult> SearchOrderPaginate([FromQuery] OrderDTO_Filter filter) { var result = await _order.SearchOrderPaginate(filter); return(Ok(result)); }