コード例 #1
0
        private static void RecalculateBlogArchive(IRepository<BlogArchiveRecord> blogArchiveRepository, IRepository<CommonRecord> commonRepository, BlogPost blogPost) {
            blogArchiveRepository.Flush();

            //INFO: (erikpo) Remove all current blog archive records
            var blogArchiveRecords =
                from bar in blogArchiveRepository.Table
                where bar.Blog == blogPost.Blog.Record
                select bar;
            blogArchiveRecords.ToList().ForEach(blogArchiveRepository.Delete);

            //INFO: (erikpo) Get all blog posts for the current blog
            var postsQuery =
                from bpr in commonRepository.Table
                where bpr.ContentItemRecord.ContentType.Name == BlogPostDriver.ContentType.Name && bpr.Container.Id == blogPost.Blog.Record.Id
                orderby bpr.PublishedUtc
                select bpr;

            //INFO: (erikpo) Create a dictionary of all the year/month combinations and their count of posts that are published in this blog
            var inMemoryBlogArchives = new Dictionary<DateTime, int>(postsQuery.Count());
            foreach (var post in postsQuery) {
                if (!post.PublishedUtc.HasValue)
                    continue;

                var key = new DateTime(post.PublishedUtc.Value.Year, post.PublishedUtc.Value.Month, 1);

                if (inMemoryBlogArchives.ContainsKey(key))
                    inMemoryBlogArchives[key]++;
                else
                    inMemoryBlogArchives[key] = 1;
            }

            //INFO: (erikpo) Create the new blog archive records based on the in memory values
            foreach (KeyValuePair<DateTime, int> item in inMemoryBlogArchives) {
                blogArchiveRepository.Create(new BlogArchiveRecord {Blog = blogPost.Blog.Record, Year = item.Key.Year, Month = item.Key.Month, PostCount = item.Value});
            }
        }
コード例 #2
0
 public static string BlogPost(this UrlHelper urlHelper, BlogPost blogPost) {
     return urlHelper.BlogPost(blogPost.Blog.Slug, blogPost.Slug);
 }
コード例 #3
0
 public static string BlogPostUnpublish(this UrlHelper urlHelper, BlogPost blogPost) {
     return urlHelper.BlogPostUnpublish(blogPost.Blog.Slug, blogPost.Id);
 }
コード例 #4
0
 public void Publish(BlogPost blogPost) {
     _publishingTaskManager.DeleteTasks(blogPost.ContentItem);
     _contentManager.Publish(blogPost.ContentItem);
 }
コード例 #5
0
 public void Publish(BlogPost blogPost, DateTime scheduledPublishUtc) {
     _publishingTaskManager.Publish(blogPost.ContentItem, scheduledPublishUtc);
 }
コード例 #6
0
 public void Delete(BlogPost blogPost) {
     _publishingTaskManager.DeleteTasks(blogPost.ContentItem);
     _contentManager.Remove(blogPost.ContentItem);
 }
コード例 #7
0
 public DateTime? GetScheduledPublishUtc(BlogPost blogPost) {
     var task = _publishingTaskManager.GetPublishTask(blogPost.ContentItem);
     return (task == null ? null : task.ScheduledUtc);
 }
コード例 #8
0
 public void Unpublish(BlogPost blogPost) {
     _contentManager.Unpublish(blogPost.ContentItem);
 }
コード例 #9
0
 public static string PublishedWhen(this HtmlHelper htmlHelper, BlogPost blogPost) {
     return htmlHelper.DateTimeRelative(blogPost.As<ICommonAspect>().VersionPublishedUtc, "as a Draft");
 }
コード例 #10
0
 private static XRpcStruct CreateBlogStruct(BlogPost blogPost, UrlHelper urlHelper) {
     var url = urlHelper.AbsoluteAction(() => urlHelper.BlogPost(blogPost));
     return new XRpcStruct()
         .Set("postid", blogPost.Id)
         .Set("dateCreated", blogPost.CreatedUtc)
         .Set("title", blogPost.Title)
         .Set("wp_slug", blogPost.Slug)
         .Set("description", blogPost.Text)
         .Set("link", url)
         .Set("permaLink", url);
 }