public async Task <NewsListWithPaginationInfo> GetNewsBySourceId(Guid?id, int pageNumber) { var pageSize = Convert.ToInt32(_configuration["PageInfo:PageSize"]); var query = new GetNewsListQuery(); var news = await _mediator.Send(query); var newsPage = news .OrderByDescending(n => n.NewsDate) .Skip((pageNumber - 1) * pageSize) .Take(pageSize) .ToList(); var pageInfo = new PageInfo() { PageNumber = pageNumber, PageSize = pageSize, TotalItems = news.Count() }; var newsViewModel = newsPage.Select(n => _mapper.Map <NewsViewModel>(n)); var newsListWithPaginationInfo = new NewsListWithPaginationInfo() { NewsPerPage = newsViewModel, PageInfo = pageInfo }; return(newsListWithPaginationInfo); }
public async Task <NewsListWithPaginationInfo> GetNewsBySourceId(Guid?id, int pageNumber) { var pageSize = Convert.ToInt32(_configuration["PageInfo:PageSize"]); var news = _unitOfWork.News.FindBy(n => true, n => n.RssSource) .Where(n => id == null || n.RssSourceId.Equals(id.GetValueOrDefault())); var newsPage = await news .OrderByDescending(n => n.NewsDate) .Skip((pageNumber - 1) * pageSize) .Take(pageSize) .ToListAsync(); var pageInfo = new PageInfo() { PageNumber = pageNumber, PageSize = pageSize, TotalItems = news.Count() }; var newsViewModel = newsPage.Select(n => _mapper.Map <NewsViewModel>(n)); var newsListWithPaginationInfo = new NewsListWithPaginationInfo() { NewsPerPage = newsViewModel, PageInfo = pageInfo }; return(newsListWithPaginationInfo); }