public Blog Save(Blog blog) { oxite_Blogs_Blog blogToSave = null; if (blog.ID != Guid.Empty) { blogToSave = context.oxite_Blogs_Blogs.FirstOrDefault(a => a.SiteID == blog.Site.ID && a.BlogID == blog.ID); } if (blogToSave == null) { blogToSave = new oxite_Blogs_Blog(); blogToSave.SiteID = blog.Site.ID; blogToSave.BlogID = blog.ID != Guid.Empty ? blog.ID : Guid.NewGuid(); blogToSave.CreatedDate = blogToSave.ModifiedDate = DateTime.UtcNow; context.oxite_Blogs_Blogs.InsertOnSubmit(blogToSave); } else { blogToSave.ModifiedDate = DateTime.UtcNow; } blogToSave.CommentingDisabled = blog.CommentingDisabled; blogToSave.BlogName = blog.Name; blogToSave.Description = blog.Description ?? ""; blogToSave.DisplayName = blog.DisplayName ?? ""; context.SubmitChanges(); return(GetBlog(blogToSave.BlogName)); }
private static Post projectPost(oxite_Blogs_Post p, oxite_User u, oxite_Blogs_Blog b, IQueryable <PostComment> c, IQueryable <oxite_Blogs_PostTagRelationship> t, IQueryable <Trackback> tb) { Blog blog = new Blog(b.SiteID, b.CommentingDisabled, b.CreatedDate, b.Description, b.DisplayName, b.BlogID, b.ModifiedDate, b.BlogName); User creator = u != null ? new User(u.UserID, u.Username, u.DisplayName, u.Email, u.HashedEmail, new Language(u.oxite_Language.LanguageID) { Name = u.oxite_Language.LanguageName, DisplayName = u.oxite_Language.LanguageDisplayName }, (EntityState)u.Status) : null; return(new Post(blog, p.Body, p.BodyShort, p.CommentingDisabled, p.CreatedDate, creator, p.PostID, p.ModifiedDate, p.PublishedDate, p.Slug, (EntityState)p.State, t.Select(tag => new PostTag(tag.TagID, tag.TagDisplayName)).ToList(), p.Title, c.ToList(), tb.ToList())); }
public bool Remove(Blog blog) { bool removedBlog = false; using (TransactionScope transaction = new TransactionScope()) { oxite_Blogs_Blog foundBlog = context.oxite_Blogs_Blogs.FirstOrDefault(b => b.BlogID == blog.ID); if (foundBlog != null) { context.oxite_Blogs_Blogs.DeleteOnSubmit(foundBlog); context.SubmitChanges(); removedBlog = true; } transaction.Complete(); } return(removedBlog); }
public bool Remove(Guid siteID, string blogName) { bool removedBlog = false; using (TransactionScope transaction = new TransactionScope()) { oxite_Blogs_Blog foundBlog = context.oxite_Blogs_Blogs.FirstOrDefault(b => b.SiteID == siteID && string.Compare(b.BlogName, blogName, true) == 0); if (foundBlog != null) { context.oxite_Blogs_Blogs.DeleteOnSubmit(foundBlog); context.SubmitChanges(); removedBlog = true; } transaction.Complete(); } return(removedBlog); }
private static Blog projectBlog(oxite_Blogs_Blog blog) { return(new Blog(blog.SiteID, blog.CommentingDisabled, blog.CreatedDate, blog.Description, blog.DisplayName, blog.BlogID, blog.ModifiedDate, blog.BlogName)); }
public Post Save(Post post) { oxite_Blogs_Post postToSave = null; if (post.ID != Guid.Empty) { postToSave = context.oxite_Blogs_Posts.FirstOrDefault(p => p.PostID == post.ID); } if (postToSave == null) { postToSave = new oxite_Blogs_Post(); postToSave.PostID = post.ID != Guid.Empty ? post.ID : Guid.NewGuid(); postToSave.CreatedDate = postToSave.ModifiedDate = DateTime.UtcNow; context.oxite_Blogs_Posts.InsertOnSubmit(postToSave); } else { postToSave.ModifiedDate = DateTime.UtcNow; } postToSave.Body = post.Body; postToSave.BodyShort = post.BodyShort; postToSave.PublishedDate = post.Published; postToSave.Slug = post.Slug; postToSave.State = (byte)post.State; postToSave.Title = post.Title; postToSave.CommentingDisabled = post.CommentingDisabled; // Tags: Use existing, create new ones if needed. Don't edit old tags foreach (Tag tag in post.Tags) { oxite_Tag persistenceTag = context.oxite_Tags.Where(t => string.Compare(t.TagName, tag.Name, true) == 0).FirstOrDefault(); if (persistenceTag == null) { Guid newTagID = Guid.NewGuid(); persistenceTag = new oxite_Tag { TagName = tag.Name, CreatedDate = DateTime.UtcNow, TagID = newTagID, ParentTagID = newTagID }; context.oxite_Tags.InsertOnSubmit(persistenceTag); } if (!context.oxite_Blogs_PostTagRelationships.Any(pt => pt.PostID == postToSave.PostID && pt.TagID == persistenceTag.TagID)) { context.oxite_Blogs_PostTagRelationships.InsertOnSubmit(new oxite_Blogs_PostTagRelationship { PostID = postToSave.PostID, TagID = persistenceTag.TagID, TagDisplayName = tag.DisplayName ?? tag.Name }); } } var tagsRemoved = from t in context.oxite_Tags join pt in context.oxite_Blogs_PostTagRelationships on t.TagID equals pt.TagID where pt.PostID == postToSave.PostID && !post.Tags.Select(tag => tag.Name.ToLower()).Contains(t.TagName.ToLower()) select pt; context.oxite_Blogs_PostTagRelationships.DeleteAllOnSubmit(tagsRemoved); if (post.Blog == null || string.IsNullOrEmpty(post.Blog.Name)) { throw new InvalidOperationException("No blog was specified"); } oxite_Blogs_Blog blog = context.oxite_Blogs_Blogs.FirstOrDefault(b => string.Compare(b.BlogName, post.Blog.Name, true) == 0); if (blog == null) { throw new InvalidOperationException(string.Format("Blog {0} could not be found", post.Blog.Name)); } postToSave.BlogID = blog.BlogID; oxite_User user = context.oxite_Users.FirstOrDefault(u => u.Username == post.Creator.Name); if (user == null) { throw new InvalidOperationException(string.Format("User {0} could not be found", post.Creator.Name)); } postToSave.CreatorUserID = user.UserID; //TODO: (erikpo) Add an item to the search index //postToSave.SearchBody = postToSave.Title + string.Join("", post.Tags.Select(t => t.Name + t.DisplayName).ToArray()) + postToSave.Body + user.DisplayName + user.Username; context.SubmitChanges(); return(GetPost(postToSave.PostID)); }
private PostComment projectComment(oxite_Comment comment, oxite_Blogs_PostCommentRelationship pcr, oxite_Blogs_Post p, oxite_Blogs_Blog b, oxite_User user) { PostCommentSmall parent = comment.ParentCommentID != comment.CommentID ? getParentComment(comment.ParentCommentID) : null; Language language = new Language(comment.oxite_Language.LanguageID) { DisplayName = comment.oxite_Language.LanguageDisplayName, Name = comment.oxite_Language.LanguageName }; if (user.Username != "Anonymous") { return(new PostComment(comment.Body, comment.CreatedDate, getUserAuthenticated(comment, user), comment.CreatorIP, comment.UserAgent, comment.CommentID, language, comment.ModifiedDate, parent, new PostSmall(p.PostID, b.BlogName, p.Slug, p.Title), pcr.Slug, (EntityState)comment.State)); } else { return(new PostComment(comment.Body, comment.CreatedDate, getUserAnonymous(comment, user), comment.CreatorIP, comment.UserAgent, comment.CommentID, language, comment.ModifiedDate, parent, new PostSmall(p.PostID, b.BlogName, p.Slug, p.Title), pcr.Slug, (EntityState)comment.State)); } }