예제 #1
0
        private void GetBlogPosts(string urlFragment)
        {
            UrlFragment = urlFragment;

            var blogPostIds = _blogDbContext.Tags
                              .Where(t => t.UrlFragment == urlFragment)
                              .Select(t => t.BlogPostId).ToList();

            foreach (var id in blogPostIds)
            {
                var blogPost = _blogDbContext.BlogPosts
                               .Where(b => b.Id == id)
                               .Select(blogPost => new BlogPostSummary(blogPost.Id, blogPost.CreatedAt, blogPost.Title, blogPost.Body, blogPost.Tags)).ToList();

                BlogPosts.AddRange(blogPost);
            }

            BlogPosts = BlogPosts
                        .OrderByDescending(b => b.DateCreated).ToList();
        }