public CommentCollection FetchAll()
 {
     CommentCollection coll = new CommentCollection();
     Query qry = new Query(Comment.Schema);
     coll.LoadAndCloseReader(qry.ExecuteReader());
     return coll;
 }
Exemple #2
0
        /// <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);
        }
Exemple #3
0
        /// <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);
        }
Exemple #4
0
        private bool IsNewTrackBack(int postId, string trackbackUrl)
        {
            CommentCollection trackbacks = new CommentCollection();
            Query             q          = Comment.CreateQuery();

            q.AndWhere(Comment.Columns.PostId, postId);
            q.AndWhere(Comment.Columns.IsDeleted, false);
            q.AndWhere(Comment.Columns.IsTrackback, true);
            q.OrderByAsc(Comment.Columns.Published);
            trackbacks.LoadAndCloseReader(q.ExecuteReader());

            foreach (Comment trackback in trackbacks)
            {
                if (string.Compare(trackbackUrl, trackback.WebSite, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #5
0
        private void GetComments(XmlTextWriter writer)
        {
            CommentFilter filter = CommentFilter.FromQueryString(Request.QueryString);
            Query         q      = filter.ToQuery();

            q.AndWhere(Comment.Columns.IsDeleted, false);
            CommentCollection comments = new CommentCollection();

            comments.LoadAndCloseReader(q.ExecuteReader());


            writer.WriteStartElement("comments");
            writer.WriteAttributeString("pageIndex", q.PageIndex.ToString());
            writer.WriteAttributeString("pageSize", q.PageSize.ToString());
            writer.WriteAttributeString("totalComments", q.GetRecordCount().ToString());
            foreach (Comment coment in comments)
            {
                ConvertComentToXML(coment, writer);
            }

            writer.WriteEndElement();
        }
Exemple #6
0
        /// <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-");
            }
        }
Exemple #7
0
        /// <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;
        }
Exemple #8
0
        /// <summary>
        /// Gets the post trackbacks from the specified postId
        /// </summary>
        /// <param name="PostId"></param>
        /// <returns></returns>
        public CommentCollection PostTrackbacks(int PostId)
        {
            CommentCollection cc = ZCache.Get<CommentCollection>("Trackbacks-" + 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.AndWhere(Comment.Columns.IsTrackback, true);
                q.OrderByAsc(Comment.Columns.Published);
                cc.LoadAndCloseReader(q.ExecuteReader());
                ZCache.InsertCache("Trackbacks-" + PostId, cc, 60);
            }

            return cc;
        }
 public CommentCollection FetchByQuery(Query qry)
 {
     CommentCollection coll = new CommentCollection();
     coll.LoadAndCloseReader(qry.ExecuteReader());
     return coll;
 }
        private bool IsNewTrackBack(int postId, string trackbackUrl)
        {
            CommentCollection trackbacks = new CommentCollection();
            Query q = Comment.CreateQuery();
            q.AndWhere(Comment.Columns.PostId, postId);
            q.AndWhere(Comment.Columns.IsDeleted, false);
            q.AndWhere(Comment.Columns.IsTrackback, true);
            q.OrderByAsc(Comment.Columns.Published);
            trackbacks.LoadAndCloseReader(q.ExecuteReader());

            foreach (Comment trackback in trackbacks)
            {
                if (string.Compare(trackbackUrl, trackback.WebSite, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    return false;
                }
            }

            return true;
        }
Exemple #11
0
        /// <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-");
        }
        private void GetComments(XmlTextWriter writer)
        {
            CommentFilter filter = CommentFilter.FromQueryString(Request.QueryString);
            Query q = filter.ToQuery();
            q.AndWhere(Comment.Columns.IsDeleted, false);
            CommentCollection comments = new CommentCollection();
            comments.LoadAndCloseReader(q.ExecuteReader());

            writer.WriteStartElement("comments");
            writer.WriteAttributeString("pageIndex", q.PageIndex.ToString());
            writer.WriteAttributeString("pageSize", q.PageSize.ToString());
            writer.WriteAttributeString("totalComments", q.GetRecordCount().ToString());
            foreach (Comment coment in comments)
            {
                ConvertComentToXML(coment, writer);
            }

            writer.WriteEndElement();
        }