Exemplo n.º 1
0
        public async Task <IActionResult> Index(int page = 1)
        {
            var model = new PostListViewModel();

            model.CurrentPage = page;
            model.PostCount   = await _dbContext.BlogPosts
                                .CountAsync(x => x.SiteId == _site.Id &&
                                            !x.IsDisabled &&
                                            !x.IsHidden);

            model.PageCount = model.PostCount.GetPageCountForResults(PageSize);
            var recordSkip = ExtensionMethods.CalculateRecordSkip(PageSize, page);

            model.Posts = await _dbContext.BlogPosts
                          .Where(x => x.SiteId == _site.Id &&
                                 !x.IsDisabled &&
                                 !x.IsHidden)
                          .OrderByDescending(x => x.PublishedOn)
                          .Skip(recordSkip)
                          .Take(PageSize)
                          .ProjectTo <PostModel>()
                          .ToListAsync();

            return(View(model));
        }