Пример #1
0
        protected override string ViewLookUp(string baseName, string defaultViewName)
        {
            Category category = new CategoryController().GetCachedCategory(CategoryID, false);

            // category-name.view
            if (category.ParentId <= 0 && ViewExists(CategoryName + baseName))
            {
                return(CategoryName + baseName);
            }

            // Subcategories
            if (category.ParentId > 0)
            {
                // parent-name.child-name.view
                if (ViewExists(category.LinkName.Replace("/", ".") + baseName))
                {
                    return(category.LinkName.Replace("/", ".") + baseName);
                }

                // childcategory.parent-name.view
                if (ViewExists("childcategory." + category.Parent.LinkName + baseName))
                {
                    return("childcategory." + category.Parent.LinkName + baseName);
                }

                // childcategory.view
                if (ViewExists("childcategory" + baseName))
                {
                    return("childcategory" + baseName);
                }

                // parent-name.view
                if (ViewExists(category.Parent.LinkName + baseName))
                {
                    return(category.Parent.LinkName + baseName);
                }
            }

            // category.view
            if (ViewExists("category" + baseName))
            {
                return("category" + baseName);
            }

            // index.view
            return(base.ViewLookUp(baseName, defaultViewName));
        }
Пример #2
0
        /// <summary>
        /// Gets x amount of popular posts from the specified category Id
        /// </summary>
        /// <param name="numberOfPosts"></param>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public PostCollection PopularPosts(int numberOfPosts, int categoryId)
        {
            PostCollection pc = ZCache.Get <PostCollection>("Posts-Popular-" + numberOfPosts + "c:" + categoryId);

            if (pc == null)
            {
                Query q = PostCollection.DefaultQuery();

                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.Orders.Clear();
                q.OrderByDesc(Post.Columns.Views);
                q.Top = numberOfPosts.ToString();
                pc    = PostCollection.FetchByQuery(q);
                ZCache.InsertCache("Posts-Popular-" + numberOfPosts + "c:" + categoryId, pc, 60);
            }
            return(pc);
        }
Пример #3
0
        protected virtual object GetCategoryPosts(string key, GraffitiContext graffitiContext)
        {
            Category       category = new CategoryController().GetCachedCategory(CategoryID, false);
            int            pageSize = SiteSettings.Get().PageSize;
            PostCollection pc       =
                ZCache.Get <PostCollection>(string.Format(CacheKey, PageIndex, CategoryID, category.SortOrder, pageSize));

            if (pc == null)
            {
                pc = new PostCollection();
                Query q = PostCollection.DefaultQuery(PageIndex, pageSize, category.SortOrder);

                if (Category.IncludeChildPosts)
                {
                    if (category.ParentId > 0)
                    {
                        q.AndWhere(Post.Columns.CategoryId, CategoryID);
                    }
                    else
                    {
                        var 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
                {
                    q.AndWhere(Post.Columns.CategoryId, CategoryID);
                }
                pc.LoadAndCloseReader(q.ExecuteReader());
                ZCache.InsertCache(string.Format(CacheKey, PageIndex, CategoryID, category.SortOrder, pageSize), pc, 60);
            }

            graffitiContext.TotalRecords = category.PostCount;
            graffitiContext.PageIndex    = PageIndex;
            graffitiContext.PageSize     = SiteSettings.Get().PageSize;

            return(pc);
        }
        public CategoryPage GetCategory(string param)
        {
            var category = new CategoryController().GetCachedCategoryByLinkName(param, true);

            if (category != null)
            {
                var categoryPage = new CategoryPage();

                categoryPage.CategoryID      = category.Id;
                categoryPage.CategoryName    = category.LinkName;
                categoryPage.MetaDescription = category.MetaDescription;
                categoryPage.MetaKeywords    = category.MetaKeywords;

                return(categoryPage);
            }

            return(null);
        }
Пример #5
0
        protected override void LoadContent(GraffitiContext graffitiContext)
        {
            IsIndexable = false;

            graffitiContext["where"] = "category";

            Category category = new CategoryController().GetCachedCategory(CategoryID, false);

            if (CategoryName != null && !Util.AreEqualIgnoreCase(CategoryName, category.LinkName))
            {
                RedirectTo(category.Url);
            }

            graffitiContext["title"]    = category.Name + " : " + SiteSettings.Get().Title;
            graffitiContext["category"] = category;

            graffitiContext.RegisterOnRequestDelegate("posts", GetCategoryPosts);

            // GetCategoryPosts needs to be called so the pager works
            GetCategoryPosts("posts", graffitiContext);
        }
Пример #6
0
        public List <DynamicNavigationItem> SafeItems()
        {
            if (Items == null)
            {
                lock (lockedObject)
                {
                    if (Items == null)
                    {
                        Items = new List <DynamicNavigationItem>();

                        CategoryCollection cc = new CategoryController().GetTopLevelCachedCategories();
                        foreach (Category c in cc)
                        {
                            DynamicNavigationItem item = new DynamicNavigationItem();
                            item.CategoryId     = c.Id;
                            item.NavigationType = DynamicNavigationType.Category;
                            item.Id             = c.UniqueId;
                            Items.Add(item);
                        }
                    }
                }
            }
            return(Items);
        }
Пример #7
0
        public MetaWeblog.CategoryInfo[] getCategories(string blogid, string username, string password)
        {
            if (ValidateUser(username, password))
            {
                CategoryCollection cc = new CategoryController().GetAllTopLevelCachedCategories();
                ArrayList          al = new ArrayList();
                Macros             m  = new Macros();
                foreach (Graffiti.Core.Category c in cc)
                {
                    CategoryInfo ci = new CategoryInfo();
                    ci.categoryid  = c.Id.ToString();
                    ci.description = c.Name;
                    ci.title       = c.Name;
                    ci.htmlUrl     = m.FullUrl(c.Url);
                    ci.rssUrl      = m.FullUrl(c.Url + "feed/");
                    al.Add(ci);

                    if (c.HasChildren)
                    {
                        foreach (Core.Category child in c.Children)
                        {
                            CategoryInfo ci2 = new CategoryInfo();
                            ci2.categoryid  = child.Id.ToString();
                            ci2.description = c.Name + " > " + child.Name;
                            ci2.title       = c.Name + " > " + child.Name;
                            ci2.htmlUrl     = m.FullUrl(child.Url);
                            ci2.rssUrl      = m.FullUrl(child.Url + "feed/");
                            al.Add(ci2);
                        }
                    }
                }

                return(al.ToArray(typeof(CategoryInfo)) as CategoryInfo[]);
            }
            throw new XmlRpcFaultException(0, "User does not exist");
        }
Пример #8
0
        protected override string ViewLookUp(string baseName, string defaultViewName)
        {
            Category category = new CategoryController().GetCachedCategory(CategoryID, false);

            if (ViewExists(CategoryName + "." + PostName + baseName))
            {
                return(CategoryName + "." + PostName + baseName);
            }
            else if (ViewExists(CategoryName.Replace("/", ".") + ".post" + baseName))
            {
                return(CategoryName.Replace("/", ".") + ".post" + baseName);
            }
            else if (ViewExists(CategoryName + ".post" + baseName))
            {
                return(CategoryName + ".post" + baseName);
            }
            else if (defaultViewName == "post.view" && ViewExists(PostName + ".view"))
            {
                return(PostName + ".view");
            }
            else if (ViewExists(PostName + baseName))
            {
                return(PostName + baseName);
            }

            // Subcategories
            if (category.ParentId > 0)
            {
                // parent-name.child-name.view
                if (ViewExists(category.LinkName.Replace("/", ".") + ".post" + baseName))
                {
                    return(category.LinkName.Replace("/", ".") + ".post" + baseName);
                }

                // childcategory.parent-name.post.view
                if (ViewExists("childcategory." + category.Parent.LinkName + ".post" + baseName))
                {
                    return("childcategory." + category.Parent.LinkName + ".post" + baseName);
                }

                if (ViewExists(category.LinkName.Replace("/", ".") + baseName))
                {
                    return(category.LinkName.Replace("/", ".") + baseName);
                }

                if (ViewExists(category.Parent.LinkName + ".post" + baseName))
                {
                    return(category.Parent.LinkName + ".post" + baseName);
                }

                if (ViewExists(category.Parent.LinkName + baseName))
                {
                    return(category.Parent.LinkName + baseName);
                }
            }
            // return CategoryName.layout.view for child posts, but not CategoryName.view
            else if (ViewExists(CategoryName + baseName) && baseName != ".view")
            {
                return(CategoryName + baseName);
            }

            else if (CategoryID == CategoryController.UnCategorizedId && ViewExists("page" + baseName))
            {
                return("page" + baseName);
            }

            else if (ViewExists("post" + baseName))
            {
                return("post" + baseName);
            }

            else if (ViewExists(defaultViewName))
            {
                return(defaultViewName);
            }

            return(base.ViewLookUp(baseName, defaultViewName));
        }
Пример #9
0
        public static List <CategoryCount> GetCategoryCountForStatus(PostStatus status, string authorID)
        {
            List <CategoryCount> catCounts = new List <CategoryCount>();
            List <CategoryCount> final     = new List <CategoryCount>();

            DataProvider dp  = DataService.Provider;
            QueryCommand cmd = new QueryCommand(String.Empty);

            if (String.IsNullOrEmpty(authorID))
            {
                cmd.Sql = @"select c.Id, " + dp.SqlCountFunction("c.Name") + @" as IdCount, p.CategoryId from graffiti_Posts AS p
                inner join graffiti_Categories AS c on p.CategoryId = c.Id
                where p.Status = " + dp.SqlVariable("Status") + @" and p.IsDeleted = 0
                group by c.Id, p.CategoryId";
            }
            else
            {
                cmd.Sql = @"select c.Id, " + dp.SqlCountFunction("c.Name") + @" as IdCount, p.CategoryId from ((graffiti_Posts AS p
                inner join graffiti_Categories AS c on p.CategoryId = c.Id)
                inner join graffiti_Users AS u on p.CreatedBy = u.Name)
                where p.Status = " + dp.SqlVariable("Status") + @" and p.IsDeleted = 0 and u.Id = " + dp.SqlVariable("AuthorId") +
                          @" group by c.Id, p.CategoryId";
            }

            cmd.Parameters.Add(Post.FindParameter("Status")).Value = (int)status;

            if (!String.IsNullOrEmpty(authorID))
            {
                cmd.Parameters.Add("AuthorId", Convert.ToInt32(authorID), Graffiti.Core.User.FindParameter("Id").DbType);
            }

            using (IDataReader reader = DataService.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    CategoryCount catCount = new CategoryCount();
                    catCount.ID         = Int32.Parse(reader["Id"].ToString());
                    catCount.Count      = Int32.Parse(reader["IdCount"].ToString());
                    catCount.CategoryId = Int32.Parse(reader["CategoryId"].ToString());

                    catCounts.Add(catCount);
                }

                reader.Close();
            }

            // populate the category name
            CategoryCollection cats = new CategoryController().GetAllCachedCategories();

            List <CategoryCount> tempParentList = new List <CategoryCount>();

            foreach (CategoryCount cc in catCounts)
            {
                Category temp = cats.Find(
                    delegate(Category c)
                {
                    return(c.Id == cc.ID);
                });

                if (temp != null)
                {
                    cc.Name     = temp.Name;
                    cc.ParentId = temp.ParentId;
                }

                if (cc.Count > 0 && cc.ParentId >= 1)
                {
                    // if it's not already in the list, add it
                    CategoryCount parent = catCounts.Find(
                        delegate(CategoryCount cac)
                    {
                        return(cac.ID == cc.ParentId);
                    });

                    if (parent == null)
                    {
                        parent = tempParentList.Find(
                            delegate(CategoryCount cac)
                        {
                            return(cac.ID == cc.ParentId);
                        });

                        if (parent == null)
                        {
                            Category tempParent = cats.Find(
                                delegate(Category cttemp)
                            {
                                return(cttemp.Id == cc.ParentId);
                            });

                            parent          = new CategoryCount();
                            parent.ID       = tempParent.Id;
                            parent.ParentId = tempParent.ParentId;
                            parent.Name     = tempParent.Name;
                            parent.Count    = 0;

                            tempParentList.Add(parent);
                        }
                    }
                }
            }

            catCounts.AddRange(tempParentList);

            List <CategoryCount> filteredPermissions = new List <CategoryCount>();

            filteredPermissions.AddRange(catCounts);

            foreach (CategoryCount ac in catCounts)
            {
                if (!RolePermissionManager.GetPermissions(ac.CategoryId, GraffitiUsers.Current).Read)
                {
                    filteredPermissions.Remove(ac);
                }
            }

            foreach (CategoryCount ac in filteredPermissions)
            {
                CategoryCount existing = final.Find(
                    delegate(CategoryCount catcount)
                {
                    return(catcount.ID == ac.ID);
                });

                if (existing == null)
                {
                    final.Add(ac);
                }
                else
                {
                    existing.Count += ac.Count;
                }
            }

            return(final);
        }
Пример #10
0
        public IEnumerable Query(IDictionary paramaters)
        {
            string type = paramaters["type"] as string;

            if (type != null)
            {
                paramaters.Remove("type");
            }
            else
            {
                type = "post";
            }

            switch (type)
            {
            case "post":

                Query postQuery = Post.CreateQuery();
                SetLimits(postQuery, paramaters);

                string categoryName = paramaters["category"] as string;
                if (categoryName != null)
                {
                    paramaters.Remove("category");
                }

                if (categoryName == "none")
                {
                    categoryName = CategoryController.UncategorizedName;
                }

                if (categoryName != null)
                {
                    paramaters["categoryid"] = new CategoryController().GetCachedCategory(categoryName, false).Id;
                }

                if (paramaters["isDeleted"] == null)
                {
                    paramaters["isDeleted"] = false;
                }

                if (paramaters["isPublished"] == null)
                {
                    paramaters["isPublished"] = true;
                }

                string orderBy = paramaters["orderby"] as string;
                if (orderBy != null)
                {
                    paramaters.Remove("orderBy");
                }
                else
                {
                    orderBy = "Published DESC";
                }

                postQuery.Orders.Add(orderBy);

                string cacheKey = "Posts-";
                foreach (string key in paramaters.Keys)
                {
                    Column col = GetPostColumn(key);
                    postQuery.AndWhere(col, paramaters[key]);
                    cacheKey += "|" + col.Name + "|" + paramaters[key];
                }

                PostCollection pc = ZCache.Get <PostCollection>(cacheKey);
                if (pc == null)
                {
                    pc = new PostCollection();
                    pc.LoadAndCloseReader(postQuery.ExecuteReader());
                    ZCache.InsertCache(cacheKey, pc, 90);
                }
                return(pc);

            case "comment":

                break;

            case "category":

                break;
            }

            return(null);
        }
Пример #11
0
        protected override void OnLoad(EventArgs e)
        {
            Initialize();

            SiteSettings settings = SiteSettings.Get();

            string baseUrl = SiteSettings.BaseUrl;

            if (string.IsNullOrEmpty(TagName))
            {
                Category category = null;
                if (CategoryID > -1)
                {
                    category = new CategoryController().GetCachedCategory(CategoryID, false);
                }

                if (category == null)
                {
                    if (!string.IsNullOrEmpty(settings.ExternalFeedUrl) &&
                        Request.UserAgent.IndexOf("FeedBurner", StringComparison.InvariantCultureIgnoreCase) == -1)
                    {
                        Context.Response.RedirectLocation = settings.ExternalFeedUrl;
                        Context.Response.StatusCode       = 301;
                        Context.Response.End();
                    }
                }
                else if (!string.IsNullOrEmpty(category.FeedUrlOverride) &&
                         Request.UserAgent.IndexOf("FeedBurner", StringComparison.InvariantCultureIgnoreCase) == -1)
                {
                    Context.Response.RedirectLocation = category.FeedUrlOverride;
                    Context.Response.StatusCode       = 301;
                    Context.Response.End();
                }
                else if (CategoryName != null && !Util.AreEqualIgnoreCase(CategoryName, category.LinkName))
                {
                    Context.Response.RedirectLocation = new Uri(Context.Request.Url, category.Url).ToString();
                    Context.Response.StatusCode       = 301;
                    Context.Response.End();
                }

                string cacheKey = CategoryID > -1
                                                          ? "Posts-Index-" + Util.PageSize + "-" + CategoryID.ToString()
                                                          : string.Format("Posts-Categories-P:{0}-C:{1}-T:{2}-PS:{3}", 1, CategoryID,
                                                                          SortOrderType.Descending, Util.PageSize);

                PostCollection pc = ZCache.Get <PostCollection>(cacheKey);

                if (pc == null)
                {
                    Query q = PostCollection.DefaultQuery();
                    q.Top = Util.PageSize.ToString();

                    if (SiteSettings.Get().IncludeChildPosts&& macros.IsNotNull(category))
                    {
                        if (category.ParentId > 0)
                        {
                            q.AndWhere(Post.Columns.CategoryId, CategoryID);
                        }
                        else
                        {
                            var 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
                    {
                        if (CategoryID > 0)
                        {
                            q.AndWhere(Post.Columns.CategoryId, CategoryID);
                        }
                    }

                    pc = new PostCollection();
                    pc.LoadAndCloseReader(q.ExecuteReader());

                    PostCollection permissionsFiltered = new PostCollection();

                    permissionsFiltered.AddRange(pc);

                    foreach (Post p in pc)
                    {
                        if (!RolePermissionManager.GetPermissions(p.CategoryId, GraffitiUsers.Current).Read)
                        {
                            permissionsFiltered.Remove(p);
                        }
                    }

                    ZCache.InsertCache(cacheKey, permissionsFiltered, 90);
                    pc = permissionsFiltered;
                }

                ValidateAndSetHeaders(pc, settings, Context);

                StringWriter sw = new StringWriter();
                sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
                XmlTextWriter writer = new XmlTextWriter(sw);

                writer.WriteStartElement("rss");
                writer.WriteAttributeString("version", "2.0");
                writer.WriteAttributeString("xmlns:dc", "http://purl.org/dc/elements/1.1/");
                writer.WriteAttributeString("xmlns:slash", "http://purl.org/rss/1.0/modules/slash/");

                // Allow plugins to add additional xml namespaces
                Core.Events.Instance().ExecuteRssNamespace(writer);

                writer.WriteStartElement("channel");
                WriteChannel(writer, category, settings);

                // Allow plugins to add additional xml to the <channel>
                Core.Events.Instance().ExecuteRssChannel(writer);

                foreach (Post p in pc)
                {
                    writer.WriteStartElement("item");
                    WriteItem(writer, p, settings, baseUrl);

                    // Allow plugins to add additional xml to the <item>
                    Core.Events.Instance().ExecuteRssItem(writer, p);

                    writer.WriteEndElement();                     // End Item
                }

                writer.WriteEndElement();                 // End Channel
                writer.WriteEndElement();                 // End Document

                // save XML into response
                Context.Response.ContentEncoding = Encoding.UTF8;
                Context.Response.ContentType     = "application/rss+xml";
                Context.Response.Write(sw.ToString());
            }
            else
            {
                PostCollection pc = GetTaggedPosts(TagName);

                ValidateAndSetHeaders(pc, settings, Context);

                StringWriter sw = new StringWriter();
                sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
                XmlTextWriter writer = new XmlTextWriter(sw);

                writer.WriteStartElement("rss");
                writer.WriteAttributeString("version", "2.0");
                writer.WriteAttributeString("xmlns:dc", "http://purl.org/dc/elements/1.1/");
                writer.WriteAttributeString("xmlns:slash", "http://purl.org/rss/1.0/modules/slash/");

                Core.Events.Instance().ExecuteRssNamespace(writer);

                writer.WriteStartElement("channel");
                WriteChannel(writer, TagName, settings);

                // Allow plugins to add additional xml to the <channel>
                Core.Events.Instance().ExecuteRssChannel(writer);

                foreach (Post p in pc)
                {
                    writer.WriteStartElement("item");
                    WriteItem(writer, p, settings, baseUrl);

                    Core.Events.Instance().ExecuteRssItem(writer, p);

                    writer.WriteEndElement();                     // End Item
                }

                writer.WriteEndElement();                 // End Channel
                writer.WriteEndElement();                 // End Document

                Context.Response.ContentEncoding = Encoding.UTF8;
                Context.Response.ContentType     = "application/rss+xml";
                Context.Response.Write(sw.ToString());
            }
        }
Пример #12
0
        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");
        }
Пример #13
0
        protected override void BeforeValidate()
        {
            base.BeforeValidate();

            if (IsNew)
            {
                if (UniqueId == Guid.Empty)
                {
                    UniqueId = Guid.NewGuid();
                }
            }

            if (string.IsNullOrEmpty(FormattedName))
            {
                FormattedName = Util.CleanForUrl(Name);
            }

            //We append the parent link name if it exists
            if (ParentId <= 0)
            {
                LinkName = Util.CleanForUrl(FormattedName);
            }
            else
            {
                LinkName = new CategoryController().GetCachedCategory(ParentId, false).LinkName + "/" + Util.CleanForUrl(FormattedName);
            }

            if (!Util.IsValidFileName(LinkName))
            {
                throw new Exception("Sorry, you cannot use the reserved word *" + LinkName + "* for a file name.");
            }

            if (string.IsNullOrEmpty(FeedUrlOverride))
            {
                FeedUrlOverride = null;
            }

            //We need to protected against category names colliding with uncategorized posts.
            //Uncategorized posts also do the same check
            if (Name != CategoryController.UncategorizedName)
            {
                Query q = Post.CreateQuery();
                q.AndWhere(Post.Columns.Name, LinkName);
                q.AndWhere(Post.Columns.CategoryId, CategoryController.UnCategorizedId);
                if (q.GetRecordCount() > 0)
                {
                    throw new Exception("Categories cannot have the same name as an uncategorized post");
                }
            }

            //Check for changes. At this time, we do not support renaming
            //categories if it has a post.
            //if(__initialCategoryName != null && __initialCategoryName != LinkName)
            //{
            //    Query q = Post.CreateQuery();
            //    q.AddWhere(Post.Columns.CategoryId, Id);
            //    if (q.GetRecordCount() > 0)
            //        throw new Exception("Sorry, at this time you cannot rename a category with posts in it.");
            //}

            if (string.IsNullOrEmpty(Body) || Body == "<p>&nbsp;</p>")
            {
                Body = null;
            }
        }