public async Task <PaginatedResponse <List <News> > > GetNewsesFiltered(FilterNewsDTO filterNewsDTO) { var responseHTTP = await _httpService.Post <FilterNewsDTO, List <News> >($"{url}/filter", filterNewsDTO, includeToken : false); var totalAmountPages = int.Parse(responseHTTP.HttpResponseMessage.Headers.GetValues("totalAmountPages").FirstOrDefault()); var paginatedResponse = new PaginatedResponse <List <News> >() { Response = responseHTTP.Response, TotalAmountPages = totalAmountPages }; return(paginatedResponse); }
public async Task <ActionResult <List <News> > > Filter(FilterNewsDTO filterNewsDTO) { var modelQueryable = _context.News.AsQueryable(); if (!string.IsNullOrWhiteSpace(filterNewsDTO.Title)) { modelQueryable = modelQueryable.Where(o => o.Title.Contains(filterNewsDTO.Title)); } if (filterNewsDTO.CategoryId != 0) { modelQueryable = modelQueryable. Where(o => o.NewsCategories. Select(x => x.CategoryId). Contains(filterNewsDTO.CategoryId)); } await HttpContext.InsertPaginationParametersInResponse(modelQueryable, filterNewsDTO.RecordsPerPage); var model = await modelQueryable.Paginate(filterNewsDTO.Pagination).ToListAsync(); return(model); }