Stephen2

Schedule Publish of a BlogPost

Mar 26th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. var blogsManager = BlogsManager.GetManager();
  2. var blog = blogsManager.GetBlogs().Single();
  3. var blogPost = blogsManager.CreateBlogPost();
  4. blogPost.Parent = blog;
  5. blogPost.Title = "Test post 2";
  6. blogPost.Content = "<p>Dad, what's the point of this story?</p><p>I like stories...</p>";
  7. blogPost.Summary = "Awesome summary";
  8. blogPost.UrlName = Regex.Replace(blogPost.Title, UrlNameCharsToReplace, UrlNameReplaceString);
  9.  
  10. //Publish in future
  11. var dateToPublish = DateTime.UtcNow.AddMinutes(2);
  12. blogPost.PublicationDate = dateToPublish;
  13. blogsManager.Lifecycle.CheckOut(blogPost);
  14. blogsManager.SaveChanges();
  15.  
  16. var bag = new Dictionary<string, string> {
  17.     { "ContentType", typeof(BlogPost).FullName }
  18. };
  19.  
  20. WorkflowManager.MessageWorkflow(blogPost.Id, typeof(BlogPost), null, "Schedule", true, bag);
Advertisement
Add Comment
Please, Sign In to add comment