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 <List <NewsDto> > Handle(GetNewsListQuery request, CancellationToken cancellationToken) { var pageSize = Convert.ToInt32(_configuration["PageInfo:PageSize"]); var news = await _dbContext.News .OrderByDescending(n => n.NewsDate) .AsNoTracking() .ToListAsync(cancellationToken); return(news.Select(n => _mapper.Map <NewsDto>(n)).ToList()); }