예제 #1
0
        public async Task <IActionResult> GetList([FromQuery] SimplePaginationModel pagination)
        {
            return(await this.Execute(false, true, async() =>
            {
                NewsListPaginatedModel result = await this.news.GetList(pagination);

                return this.Ok(result);
            }));
        }
예제 #2
0
        public async Task <NewsListPaginatedModel> GetList(SimplePaginationModel pagination)
        {
            IEnumerable <NewsListModel> news = this.db.News
                                               .OrderByDescending(n => n.CreationDate)
                                               .ProjectTo <NewsListModel>()
                                               .ToList();

            int newsCount = news.Count();

            news = news.Skip(pagination.Size * (pagination.Page - 1)).Take(pagination.Size).ToList();

            return(new NewsListPaginatedModel
            {
                News = news,
                NewsCount = newsCount
            });
        }