public IActionResult Index(BlogPostsRequestViewModel request) { var blogPosts = _blogPostRepository.ToPagedListOfPublishedBlogPosts(request); var model = new BlogIndexViewModel() { BlogPosts = blogPosts }; return(View(model)); }
public IPagedList <BlogPostWithContentTagsViewModel> ToPagedListOfPublishedBlogPosts(BlogPostsRequestViewModel request) { var results = _dbSet .FilterByTag(request.tag, _dbContext) .Where(w => w.IsPublished); if (!string.IsNullOrEmpty(request.q)) { results = results.Where(w => w.Title.Contains(request.q) || w.Body.Contains(request.q)); } return(results.Include(i => i.BlogPostsContentTags) .OrderByDescending(o => o.DatePublished) .Select(post => new BlogPostWithContentTagsViewModel() { BlogPost = post, ContentTags = _dbContext.BlogPostsContentTags .Where(w => w.BlogPostId == post.Id) .Select(s => s.ContentTag) .ToList() }) .ToPagedList(request.pageSize, request.page)); }