コード例 #1
0
        public ActionResult SaveNew(string name, int? parentCategoryId)
        {
            Category category = new Category
             {
            Name = name,
            Site = Context.ManagedSite
             };

             if (parentCategoryId.HasValue)
            category.SetParentCategory(categoryService.GetById(parentCategoryId.Value));
             else
            category.SetParentCategory(null);

             try
             {
               categoryService.Save(category);

               // Show the confirmation message
               MessageModel message = new MessageModel
               {
              Text = GlobalResource("Message_CategorySaved"),
              Icon = MessageModel.MessageIcon.Info,
              CssClass = "margin-topbottom"
               };

               return View("MessageUserControl", message);
             }
             catch (Exception ex)
             {
            log.Error("AdminCategoryController.SaveNew", ex);

            MessageModel message = new MessageModel
            {
               Text = GlobalResource("Message_GenericError"),
               Icon = MessageModel.MessageIcon.Alert,
               CssClass = "margin-topbottom"
            };

            return View("MessageUserControl", message);
             }
        }
コード例 #2
0
ファイル: CategoryExtensions.cs プロジェクト: aozora/arashi
        public static void SetParentCategory(this Category category, Category newParentCategory)
        {
            if (category.Id != -1 && newParentCategory == category.ParentCategory)
             {
            return; // don't do anything when the parent stays the same.
             }

             if (category.ParentCategory != null)
             {
            IList<Category> categoryList = category.ParentCategory.ChildCategories;

            categoryList.Remove(category);

            // Re-organize sibling positions.
            for (int i = 0; i < categoryList.Count; i++)
            {
               categoryList[i].SetPosition(i);
            }
             }
             else if (category.Site.RootCategories.Contains(category))
             {
            category.Site.RootCategories.Remove(category);
            // Re-organize sibling positions.
            for (int i = 0; i < category.Site.RootCategories.Count; i++)
            {
               category.Site.RootCategories[i].SetPosition(i);
            }
             }

             category.ParentCategory = newParentCategory;
             if (newParentCategory != null)
             {
            category.SetPosition(newParentCategory.ChildCategories.Count);
            newParentCategory.ChildCategories.Add(category);
             }
             else
             {
            category.SetPosition(category.Site.RootCategories.Count);
            category.Site.RootCategories.Add(category);
             }
        }
コード例 #3
0
ファイル: CategoryService.cs プロジェクト: aozora/arashi
        public void Delete(Category category)
        {
            if (category.ChildCategories.Count > 0)
            throw new ArgumentException("CategoryHasChildCategoriesException");

             if (category.ContentItems.Count > 0)
            throw new ArgumentException("CategoryHasContentItemsException");

             //using (NHTransactionScope tx = new NHTransactionScope())
             //{
             Repository<Category>.Delete(category);
             //tx.VoteCommit();
             //}

             if (category.ParentCategory != null)
             {
            RemoveCategoryAndReorderSiblings(category, category.ParentCategory.ChildCategories);
             }
             else
             {
            RemoveCategoryAndReorderSiblings(category, category.Site.RootCategories);
             }
        }
コード例 #4
0
        /// <summary>
        /// Render the child categories
        /// </summary>
        /// <param name="html"></param>
        /// <param name="category"></param>
        private void RenderChildCategories(StringBuilder html, Category category)
        {
            if (category.ChildCategories.Count > 0)
             {
            html.Append("<ul class=\"children\">");

            foreach (Category childCategory in category.ChildCategories)
            {
               html.AppendFormat("<li class=\"cat-item cat-item-{0}\">", childCategory.Id.ToString());

               // Render a category
               html.AppendFormat("<a title=\"View all posts filed under {0}\" href=\"{1}\">{0}</a>", childCategory.Name, GetAbsoluteUrl(childCategory.GetCategoryUrl()));

               RenderChildCategories(html, childCategory);

               html.Append("</li>");
            }

            html.Append("</ul>");
             }
        }
コード例 #5
0
ファイル: CategoryService.cs プロジェクト: aozora/arashi
 private void RemoveCategoryAndReorderSiblings(Category category, IList<Category> categories)
 {
     categories.Remove(category);
      for (int i = 0; i < categories.Count; i++)
      {
     categories[i].SetPosition(i);
      }
 }
コード例 #6
0
ファイル: CategoryService.cs プロジェクト: aozora/arashi
        public void Save(Category category)
        {
            //using (NHTransactionScope tx = new NHTransactionScope())
             //{
            // Check if the FriendlyName is unique
            long similarCount = GetCountForSimilarFriendlyName(category.Site, category.FriendlyName);

            if (similarCount > 0)
               category.FriendlyName = category.FriendlyName + "-" + (similarCount + 1).ToString();

            Repository<Category>.Save(category);
             //   tx.VoteCommit();
             //}
        }