public bool SavePublishedPost(BlogPostPublished post) { if (post.BlogPostTemplateId == 0) { var count = AppDbContext.Posts .Count(p => p.UrlTitle.ToLower() == post.UrlTitle.ToLower()); if (count == 0) { AppDbContext.Posts.Add(post); AppDbContext.SaveChanges(); return(true); } else { return(false); } } else { var postToUpdate = GetPostById(post.BlogPostTemplateId); if (postToUpdate != null) { postToUpdate.UpdatePost(post); AppDbContext.SaveChanges(); return(true); } return(false); } }
public void PublishDraftToPost(BlogPostDraft draft) { AppDbContext.Drafts.Remove(draft); var post = new BlogPostPublished(); post.PublishDraftToPost(draft); AppDbContext.Posts.Add(post); AppDbContext.SaveChanges(); }
public void UnPublishPostToDraft(BlogPostPublished published) { AppDbContext.Posts.Remove(published); var draft = new BlogPostDraft(); draft.UnPublishToDraft(published); AppDbContext.Drafts.Add(draft); AppDbContext.SaveChanges(); }
public bool UpdatePost(BlogPostPublished newData) { if (base.UpdatePost(newData) == false) { return(false); } TimeOfDayPublished = newData.TimeOfDayPublished; DatePublished = newData.DatePublished; return(true); }
private static IQueryable <BlogPostPublished> GenerateSamplePosts() { List <BlogPostPublished> posts = new List <BlogPostPublished>(); List <string> cats = new List <string>(); for (int i = 1; i < 12; i++) { BlogPostPublished p = new BlogPostPublished { PageTitle = $"Post Title No {i}", FullContent = $"<h3>A Sample</h3> <p>Content for post no {i}</p>", DatePublished = new DateTime(2017, i, i), TimeOfDayPublished = new TimeSpan(i, 0, 0), Author = "Nick Fisher" }; p.AddCategories("Cat" + i, "BigCat"); posts.Add(p); } return(posts.AsQueryable()); }
public void UnPublishToDraft(BlogPostPublished published) { this.BlogPostTemplateId = published.BlogPostTemplateId; base.UpdatePost(published); this.BlogPostTemplateId = 0; }