protected void AddCategoryClick(object sender, EventArgs e) { string categoryName = popAddCategory.Value; string categoryId = popAddCategory.ReferrerId; string categoryTypeName = string.Empty; // Need to figure out if this is a comms block category or a doco block category. if (!string.IsNullOrEmpty(categoryId)) { BusiBlocks.CommsBlock.News.Category news = null; try { news = NewsManager.GetCategory(categoryId); categoryTypeName = news.GetType().Name; } catch (NewsCategoryNotFoundException) { } if (news != null) { BusiBlocks.CommsBlock.News.Category childCategory = NewsManager.CreateCategory(categoryName); childCategory.ParentCategory = news; NewsManager.UpdateCategory(childCategory); this.PopulateTreeView <BusiBlocks.CommsBlock.News.Category>(NewsManager.GetAllCategories(), true, false, string.Empty); } else { BusiBlocks.DocoBlock.Category doco = null; try { doco = DocoManager.GetCategory(categoryId); categoryTypeName = doco.GetType().Name; } catch (DocoCategoryNotFoundException) { } if (doco != null) { BusiBlocks.DocoBlock.Category childDocoCategory = DocoManager.CreateCategory(categoryName); childDocoCategory.ParentCategory = doco; DocoManager.UpdateCategory(childDocoCategory); this.PopulateTreeView <BusiBlocks.DocoBlock.Category>(DocoManager.GetAllCategories(), true, false, string.Empty); } } RadTreeView1.DataBind(); RadTreeView1.FindNodeByText(categoryName).ExpandParentNodes(); RadTreeView1.FindNodeByText(categoryName).Selected = true; ((IFeedback)this.Page.Master).ShowFeedback( BusiBlocksConstants.Blocks.Administration.LongName, categoryTypeName, Feedback.Actions.Created, categoryName ); } }
protected void DeleteCategoryClick(object sender, EventArgs e) { string categoryName = string.Empty; string categoryId = popDeleteCategory.ReferrerId; string categoryTypeName = string.Empty; string parentCategoryName = string.Empty; bool deleteFailure = false; // Need to figure out if this is a comms block category or a doco block category. if (!string.IsNullOrEmpty(categoryId)) { BusiBlocks.CommsBlock.News.Category news = null; try { news = NewsManager.GetCategory(categoryId); } catch (NewsCategoryNotFoundException) { } if (news != null) { categoryTypeName = news.GetType().Name; categoryName = news.Name; // Don't allow the root category to be deleted. if (news.ParentCategory == null) { ((IFeedback)this.Page.Master).ShowFeedback( BusiBlocksConstants.Blocks.Administration.LongName, news.Name, Feedback.Actions.Error, "Cannot delete the highest level category" ); return; } parentCategoryName = news.ParentCategory.Name; IList <BusiBlocks.CommsBlock.News.Item> newsItems = NewsManager.GetItems(news, true); IList <BusiBlocks.CommsBlock.News.Category> newsSubCategories = NewsManager.GetCategories(news.Id, true); // NewsManager.GetCategories returns the root category, so it will always have at least one item if (newsSubCategories.Count <= 1 && newsItems.Count == 0) { NewsManager.DeleteCategory(news); PopulateTreeView <BusiBlocks.CommsBlock.News.Category>(NewsManager.GetViewableCategories(Page.User.Identity.Name), true, false, string.Empty); } else { deleteFailure = true; } } else { BusiBlocks.DocoBlock.Category doco = null; try { doco = DocoManager.GetCategory(categoryId); } catch (DocoCategoryNotFoundException) { } if (doco != null) { categoryTypeName = doco.GetType().Name; categoryName = doco.DisplayName; parentCategoryName = doco.ParentCategory.DisplayName; IList <Article> docoItems = DocoManager.GetArticles(doco, ArticleStatus.All, true); IList <BusiBlocks.DocoBlock.Category> docoSubCategories = DocoManager.GetAllCategoriesBelow(doco.Id); if (docoSubCategories.Count == 0 && docoItems.Count == 0) { DocoManager.DeleteCategory(doco); this.PopulateTreeView <BusiBlocks.DocoBlock.Category>(DocoManager.GetAllCategories(), true, false, string.Empty); } else { deleteFailure = true; } } } RadTreeView1.DataBind(); } //Displaying feedback. if (deleteFailure) { ((IFeedback)this.Page.Master).ShowFeedback( BusiBlocksConstants.Blocks.Administration.LongName, categoryTypeName, Feedback.Actions.Error, ErrorCategoryNotEmpty ); RadTreeView1.FindNodeByText(categoryName).ExpandParentNodes(); RadTreeView1.FindNodeByText(categoryName).Selected = true; } else { ((IFeedback)this.Page.Master).ShowFeedback( BusiBlocksConstants.Blocks.Administration.LongName, categoryTypeName, Feedback.Actions.Deleted, categoryName ); RadTreeView1.FindNodeByText(parentCategoryName).ExpandParentNodes(); RadTreeView1.FindNodeByText(parentCategoryName).Selected = true; } }
/// <summary> /// Using the category data source, create the tree. Any categories with no parent will become root /// nodes. Any categories with a parent will be added to its parent. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="categoryDataSource"></param> /// <param name="isAdmin"></param> /// <param name="showNodeItems"></param> protected void CreateCategoryTreeView <T>(IList <T> categoryDataSource, bool isAdmin, bool showNodeItems) { var t = typeof(T); //add root node var allNodes = from nodes in categoryDataSource select nodes; // Create the sort list. List <SortStruct> sortList = new List <SortStruct>(); foreach (var r in allNodes) { if (r.GetType().FullName.Contains("News")) { BusiBlocks.CommsBlock.News.Category category = r as BusiBlocks.CommsBlock.News.Category; string parentId = (category.ParentCategory != null) ? category.ParentCategory.Id : string.Empty; sortList.Add(new SortStruct() { Id = category.Id, ParentId = parentId, Original = category, OriginalType = category.GetType() }); } else if (r.GetType().FullName.Contains("Doco")) { BusiBlocks.DocoBlock.Category category = r as BusiBlocks.DocoBlock.Category; string parentId = (category.ParentCategory != null) ? category.ParentCategory.Id : string.Empty; sortList.Add(new SortStruct() { Id = category.Id, ParentId = parentId, Original = category, OriginalType = category.GetType() }); } } int circuitBreaker = 0; do { // Find the o-level objects. IList <SortStruct> oLevels = Add0Levels(sortList, isAdmin, showNodeItems); foreach (SortStruct item in oLevels) { sortList.Remove(item); } circuitBreaker++; }while (sortList.Count > 0 && circuitBreaker < 100); }