/// <summary> /// Gets the last x amount of comments from the specified category Id /// </summary> /// <param name="numberOfComments"></param> /// <param name="categoryId"></param> /// <returns></returns> public CommentCollection RecentComments(int numberOfComments, int categoryId) { CommentCollection cc = ZCache.Get <CommentCollection>("Comments-Recent-" + numberOfComments + "c:" + categoryId); if (cc == null) { cc = new CommentCollection(); Query q = Comment.CreateQuery(); q.AndWhere(Comment.Columns.IsDeleted, false); q.AndWhere(Comment.Columns.IsPublished, true); if (categoryId > 0) { Category category = new CategoryController().GetCachedCategory(categoryId, true); if (category != null) { if (category.ParentId > 0) { q.AndWhere(Post.Columns.CategoryId, categoryId); } else { List <int> ids = new List <int>(category.Children.Count + 1); foreach (Category child in category.Children) { ids.Add(child.Id); } ids.Add(category.Id); q.AndInWhere(Post.Columns.CategoryId, ids.ToArray()); } } else { //this should result in no data, but it will signal to //the end user to edit/remove this widget q.AndWhere(Post.Columns.CategoryId, categoryId); } } q.Top = numberOfComments.ToString(); q.OrderByDesc(Comment.Columns.Id); cc.LoadAndCloseReader(q.ExecuteReader()); ZCache.InsertCache("Comments-Recent-" + numberOfComments + "c:" + categoryId, cc, 60); } return(cc); }
public static void UpdateCommentCount(int postid) { QueryCommand command = null; DataProvider dp = DataService.Provider; if (Util.IsAccess) { Query q1 = Comment.CreateQuery(); q1.AndWhere(Comment.Columns.PostId, postid); q1.AndWhere(Comment.Columns.IsPublished, true); q1.AndWhere(Comment.Columns.IsDeleted, false); int Comment_Count = q1.GetRecordCount(); Query q2 = Comment.CreateQuery(); q2.AndWhere(Comment.Columns.PostId, postid); q2.AndWhere(Comment.Columns.IsPublished, false); q2.AndWhere(Comment.Columns.IsDeleted, false); int Pending_Comment_Count = q2.GetRecordCount(); command = new QueryCommand("UPDATE graffiti_Posts Set Comment_Count = " + dp.SqlVariable("Comment_Count") + ", Pending_Comment_Count = " + dp.SqlVariable("Pending_Comment_Count") + " WHERE Id = " + dp.SqlVariable("Id")); var parameters = GenerateParameters(); command.Parameters.Add(FindParameter(parameters, "Comment_Count")).Value = Comment_Count; command.Parameters.Add(FindParameter(parameters, "Pending_Comment_Count")).Value = Pending_Comment_Count; command.Parameters.Add(FindParameter(parameters, "Id")).Value = postid; } else { string sql = @"Update graffiti_Posts Set Comment_Count = (Select " + dp.SqlCountFunction() + @" FROM graffiti_Comments AS c where c.PostId = " + dp.SqlVariable("Id") + @" and c.IsPublished = 1 and c.IsDeleted = 0), Pending_Comment_Count = (Select " + dp.SqlCountFunction() + @" FROM graffiti_Comments AS c where c.PostId = " + dp.SqlVariable("Id") + @" and c.IsPublished = 0 and c.IsDeleted = 0) Where Id = " + dp.SqlVariable("Id"); command = new QueryCommand(sql); command.Parameters.Add(FindParameter("Id")).Value = postid; } DataService.ExecuteNonQuery(command); }
/// <summary> /// Gets the post feedback from the specified postId /// </summary> /// <param name="PostId"></param> /// <returns></returns> public CommentCollection PostFeedback(int PostId) { CommentCollection cc = ZCache.Get <CommentCollection>("Feedback-" + PostId); if (cc == null) { cc = new CommentCollection(); Query q = Comment.CreateQuery(); q.AndWhere(Comment.Columns.PostId, PostId); q.AndWhere(Comment.Columns.IsPublished, true); q.AndWhere(Comment.Columns.IsDeleted, false); q.OrderByAsc(Comment.Columns.Published); cc.LoadAndCloseReader(q.ExecuteReader()); ZCache.InsertCache("Feedback-" + PostId, cc, 10); } return(cc); }
/// <summary> /// Renames a user account /// </summary> public static void RenameUser(string oldUserName, string newUserName) { if (!controller.CanDeleteUsers) { throw new Exception("The membership system in use does not support deleting users"); } IGraffitiUser user = GetUser(oldUserName); if (user == null) { throw new Exception("The supplied username does not exist!"); } oldUserName = oldUserName.ToLower(); newUserName = newUserName.ToLower(); controller.RenameUser(oldUserName, newUserName); // Check if the user has created/modified any content PostCollection pc = new PostCollection(); Query q = Post.CreateQuery(); q.OrWhere(Post.Columns.UserName, oldUserName); q.OrWhere(Post.Columns.CreatedBy, oldUserName); q.OrWhere(Post.Columns.ModifiedBy, oldUserName); pc.LoadAndCloseReader(q.ExecuteReader()); if (pc != null && pc.Count > 0) { foreach (Post p in pc) { if (p.UserName == oldUserName) { p.UserName = newUserName; } if (p.ModifiedBy == oldUserName) { p.ModifiedBy = newUserName; } if (p.CreatedBy == oldUserName) { p.CreatedBy = newUserName; } p.Save(); } } // Check if user has created any comments CommentCollection cc = new CommentCollection(); q = Comment.CreateQuery(); q.OrWhere(Comment.Columns.UserName, oldUserName); q.OrWhere(Comment.Columns.CreatedBy, oldUserName); q.OrWhere(Comment.Columns.ModifiedBy, oldUserName); cc.LoadAndCloseReader(q.ExecuteReader()); if (cc != null && cc.Count > 0) { foreach (Comment c in cc) { if (c.UserName == oldUserName) { c.UserName = newUserName; } if (c.ModifiedBy == oldUserName) { c.ModifiedBy = newUserName; } if (c.CreatedBy == oldUserName) { c.CreatedBy = newUserName; } c.Save(); } } //Check if the user has created any post versions VersionStoreCollection vsc = new VersionStoreCollection(); vsc = VersionStoreCollection.FetchAll(); if (vsc != null && vsc.Count > 0) { foreach (VersionStore v in vsc) { Post vp = ObjectManager.ConvertToObject <Graffiti.Core.Post>(v.Data); if (v.CreatedBy == oldUserName) { v.CreatedBy = newUserName; } if (v.Type == "post/xml") { if (vp.UserName == oldUserName) { vp.UserName = newUserName; } if (vp.ModifiedBy == oldUserName) { vp.ModifiedBy = newUserName; } if (vp.CreatedBy == oldUserName) { vp.CreatedBy = newUserName; } v.Data = vp.ToXML(); } v.Save(); } } ZCache.RemoveCache("user-" + oldUserName); // Clear roles cache if (user.Roles != null && user.Roles.Length > 0) { ZCache.RemoveByPattern("usersByRole-"); } }