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