Example #1
0
    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        BusiBlocksTreeView categories = NewsManager.GetCategoriesItemsTree(Page.User.Identity.Name);

        object itemList = ViewState[ItemList];

        if (itemList != null)
        {
            IList <Item> items = new List <Item>();
            if (itemList.ToString().Equals("All"))
            {
                items = NewsManager.GetItems();
            }
            else
            {
                if (!string.IsNullOrEmpty(itemList.ToString()))
                {
                    string[] arr = itemList.ToString().Split(',');
                    foreach (string itemId in arr)
                    {
                        Item item = NewsManager.GetItem(itemId);
                        if (categories.Contains(item.Category.Id))
                        {
                            items.Add(NewsManager.GetItem(itemId));
                        }
                    }
                }
            }
            if (RadGrid1.MasterTableView.SortExpressions.Count == 0)
            {
                GridSortExpression expression = new GridSortExpression();
                expression.FieldName = "Item.UpdateDate";
                expression.SortOrder = GridSortOrder.Descending;
                RadGrid1.MasterTableView.SortExpressions.AddSortExpression(expression);
            }
            var allowedList =
                (from item in items where SecurityHelper.CanUserView(Page.User.Identity.Name, item.Category.Id) select new RepeaterItem {
                Item = item, TrafficLightUrl = GetUserStatus(item)
            }).ToList();
            RadGrid1.DataSource = allowedList;
        }
    }
Example #2
0
        public static BusiBlocksTreeView GetCategoriesItemsTree(bool includeItems, string username)
        {
            BusiBlocksTreeView tree = new BusiBlocksTreeView {
                Nodes = new List <BusiBlocksTreeNode>()
            };
            IList <Category> categories = NewsManager.GetAllCategories();

            var rootCategories = from x in categories where x.ParentCategory == null select x;

            int maxLevel = 100;

            foreach (Category category in rootCategories)
            {
                BusiBlocksTreeNode node = new BusiBlocksTreeNode {
                    Name = category.Name, Id = category.Id, IsFolder = true, ChildNodes = new List <BusiBlocksTreeNode>()
                };
                if (BusiBlocks.SecurityHelper.CanUserView(username, node.Id))
                {
                    tree.Nodes.Add(node);
                    IList <Item> items = NewsManager.GetItems(category, false);
                    if (items.Count > 0 && includeItems)
                    {
                        foreach (Item item in items)
                        {
                            if (BusiBlocks.SecurityHelper.CanUserView(username, category.Id))
                            {
                                node.ChildNodes.Add(new BusiBlocksTreeNode {
                                    Id = item.Id, Name = item.Title, IsFolder = false
                                });
                            }
                        }
                    }
                    CreateCategoryStructure(node, categories, category, maxLevel, 0, includeItems, username);
                }
            }
            return(tree);
        }
Example #3
0
        private static BusiBlocksTreeView PopulateTreeView(string username)
        {
            var catTreeView = new BusiBlocksTreeView();

            IList <Category> cats = GetAllCategories();

            IList <Category> toRemove = new List <Category>();

            foreach (Category cat in cats)
            {
                // Remove this category from the list if it is not viewable by this user.
                if (!SecurityHelper.CanUserView(username, cat.Id))
                {
                    toRemove.Add(cat);
                }
            }
            foreach (Category cat in toRemove)
            {
                cats.Remove(cat);
            }

            // Need to form the hierarchical structure by selecting the categories with no parent
            // and then adding sub collections of categories with the chosen parent.

            var noParent =
                from x in cats
                where x.ParentCategory == null
                select x;

            int maxLevel = 20;

            if (!noParent.Any())
            {
                // Try to pick the "all docs" category.
                noParent =
                    from x in cats
                    where x.DisplayName.Equals("All Documents")
                    select x;
            }
            foreach (Category cat in noParent)
            {
                var node = new BusiBlocksTreeNode {
                    Id = cat.Id, Name = cat.DisplayName, IsFolder = true
                };
                IList <Article> items = GetArticles(cat, ArticleStatus.All, false);
                foreach (Article item in items)
                {
                    node.ChildNodes.Add(new BusiBlocksTreeNode {
                        Id = item.Id, Name = item.Name, IsFolder = false
                    });
                }
                catTreeView.Nodes.Add(node);
                PopulateSub(cat, cats, node, maxLevel, 0);
            }
            // todo Remove this commented out block when we're sure it isn't doing anything.
            //// Set the selected category.
            //if (noParent.Any())
            //{
            //    Category cat = noParent.First();
            //}
            return(catTreeView);
        }