예제 #1
0
 public BlogPostViewModel(
     BlogPost post,
     IReadOnlyList<BlogCategory> categories,
     IReadOnlyList<DateTime> archive) : base(categories, archive)
 {
     Post = post;
 }
예제 #2
0
 public BlogPostViewModel(
     BlogPost post,
     IReadOnlyList<BlogCategory> categories,
     IReadOnlyList<DateTime> archive,
     IReadOnlyList<string> authors)
     : base(categories, archive, authors)
 {
     Post = post;
 }
예제 #3
0
        public static IHtmlString RenderCategoryList(this HtmlHelper helper, BlogPost post)
        {
            var writer = new HtmlTextWriter(new StringWriter());
            for (int i = 0; i < post.Categories.Count; i++)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Href, LinkHelper.GetLink(post.Categories[i]));
                writer.RenderBeginTag(HtmlTextWriterTag.A);
                writer.Write(post.Categories[i].Title);
                writer.RenderEndTag();

                if (i != post.Categories.Count - 1)
                {
                    writer.Write(", ");
                }
            }
            return MvcHtmlString.Create(writer.InnerWriter.ToString());
        }
예제 #4
0
 public static string GetLink(this HtmlHelper helper, BlogPost post)
 {
     return LinkHelper.GetLink(post);
 }
예제 #5
0
 public static string GetLink(BlogPost post)
 {
     return $"/blog/{post.PostedAt.Year}/{post.PostedAt.Month:00}/{post.Slug}";
 }
예제 #6
0
 public static string GetLink(BlogPost post)
 {
     return string.Format("/blog/{0}/{1:00}/{2}", post.PostedAt.Year, post.PostedAt.Month, post.Slug);
 }
예제 #7
0
 private void AddToArchive(BlogPost post)
 {
     var year = post.PostedAt.Year;
     var month = post.PostedAt.Month;
     if (!_yearMonthToPostsLookup.ContainsKey(year))
     {
         _yearMonthToPostsLookup.Add(year, new Dictionary<int, List<BlogPost>>());
     }
     if (!_yearMonthToPostsLookup[year].ContainsKey(month))
     {
         _yearMonthToPostsLookup[year].Add(month, new List<BlogPost>());
         _archive.Add(new DateTime(year, month, 1, 0, 0, 0));
     }
     _yearMonthToPostsLookup[year][month].Add(post);
 }
예제 #8
0
 private void AddToLookup(BlogPost post)
 {
     _idToPostLookup.Add(post.Id, post);
 }
예제 #9
0
 private void AddToLookup(BlogPost post)
 {
     _idToPostLookup.Add(post.Id, post);
 }
예제 #10
0
        public BlogPost GetBlogPost(int year, int month, string slug)
        {
            var id = BlogPost.GetId(year, month, slug);

            return(_idToPostLookup.ContainsKey(id) ? _idToPostLookup[id] : null);
        }