public static void DestroyDeletedPost(int postid) { Post p = new Post(postid); // Check if post is featured in it's category before deletion Core.Category c = p.Category; if (p.Id == c.FeaturedId) { c.FeaturedId = 0; c.Save(); } // Check site featured post SiteSettings settings = SiteSettings.Get(); if (p.Id == settings.FeaturedId) { settings.FeaturedId = 0; settings.Save(); } PostStatistic.Destroy(PostStatistic.Columns.PostId, postid); Tag.Destroy(Tag.Columns.PostId, postid); Comment.Destroy(Comment.Columns.PostId, postid); DataService.ExecuteNonQuery(new QueryCommand("delete from graffiti_VersionStore where Type = 'post/xml' and ItemId = " + postid)); Post.Destroy(postid); DeletePostDirectory(p); }
private static Graffiti.Core.Category AddOrFetchCategory(string name, IGraffitiUser user) { int index = name.IndexOf(">"); if (index > -1) { string parentName = name.Substring(0, index).Trim(); string childName = name.Substring(index + 1).Trim(); Graffiti.Core.Category parent = new CategoryController().GetCachedCategory(parentName, true); if (parent != null) { foreach (Graffiti.Core.Category childCategory in parent.Children) { if (Util.AreEqualIgnoreCase(childCategory.Name, childName)) { return(childCategory); } } if (GraffitiUsers.IsAdmin(user)) { Core.Category child = new Core.Category(); child.Name = HttpUtility.HtmlEncode(childName); child.ParentId = parent.Id; child.Save(); return(child); } } else { if (GraffitiUsers.IsAdmin(user)) { parent = new Core.Category(); parent.Name = HttpUtility.HtmlEncode(parentName); parent.Save(); Core.Category child = new Core.Category(); child.Name = HttpUtility.HtmlEncode(childName); child.ParentId = parent.Id; child.Save(); return(child); } } } else { Core.Category category = new CategoryController().GetCachedCategory(name, true); if (category == null) { if (GraffitiUsers.IsAdmin(user)) { category = new Core.Category(); category.Name = name; category.Save(); } } return(category); } Log.Warn("Categories", "The user {0} does not have permission to create the category {1}", user.ProperName, HttpUtility.HtmlEncode(name)); throw new Exception("You do not have permission to create a new category or sub-category"); }
private static Graffiti.Core.Category AddOrFetchCategory(string name, IGraffitiUser user) { int index = name.IndexOf(">"); if (index > -1) { string parentName = name.Substring(0, index).Trim(); string childName = name.Substring(index+1).Trim(); Graffiti.Core.Category parent = new CategoryController().GetCachedCategory(parentName, true); if (parent != null) { foreach (Graffiti.Core.Category childCategory in parent.Children) { if (Util.AreEqualIgnoreCase(childCategory.Name, childName)) return childCategory; } if (GraffitiUsers.IsAdmin(user)) { Core.Category child = new Core.Category(); child.Name = HttpUtility.HtmlEncode(childName); child.ParentId = parent.Id; child.Save(); return child; } } else { if (GraffitiUsers.IsAdmin(user)) { parent = new Core.Category(); parent.Name = HttpUtility.HtmlEncode(parentName); parent.Save(); Core.Category child = new Core.Category(); child.Name = HttpUtility.HtmlEncode(childName); child.ParentId = parent.Id; child.Save(); return child; } } } else { Core.Category category = new CategoryController().GetCachedCategory(name, true); if (category == null) { if (GraffitiUsers.IsAdmin(user)) { category = new Core.Category(); category.Name = name; category.Save(); } } return category; } Log.Warn("Categories", "The user {0} does not have permission to create the category {1}", user.ProperName,HttpUtility.HtmlEncode(name)); throw new Exception("You do not have permission to create a new category or sub-category"); }