예제 #1
0
        /// <summary>
        /// add child item
        /// </summary>
        /// <param name="cat"></param>
        /// <param name="collection"></param>
        private void _addChildrend(TreeData cat, ICollection<BusinessCategory> collection)
        {
            foreach (var item in collection)
            {
                var chil = new TreeData()
                {
                    id = item.Id,
                    text = item.Name,
                    categoryId = item.CategoryId,
                    ParentId = item.CategoryParentId
                };

                cat.children.Add(chil);

                if (item.BusinessCategories != null && item.BusinessCategories.Count > 0)
                {
                    if (chil.children == null)
                        chil.children = new List<TreeData>();
                    _addChildrend(chil, item.BusinessCategories);

                }
            }
        }
예제 #2
0
        /// <summary>
        /// Get menu tree
        /// </summary>
        public void GetMenus()
        {
            var list = businessCategoryService.Get().Where(t => t.CategoryParentId == null);
            menus = new List<TreeData>();
            foreach (var item in list)
            {
                var cat = new TreeData()
                {
                    id = item.Id,
                    categoryId = item.CategoryId,
                    text = item.Name,
                    ParentId = item.CategoryParentId
                };
                menus.Add(cat);

                if (item.BusinessCategories != null && item.BusinessCategories.Count > 0)
                {
                    if (cat.children == null)
                        cat.children = new List<TreeData>();
                    _addChildrend(cat, item.BusinessCategories);

                }

            }
        }
예제 #3
0
        public JsonResult GetMenus()
        {
            var list = businessCategoryService.Get().Where(t => t.CategoryParentId == null);
            foreach (var item in list)
            {
                var cat = new TreeData()
                {
                    id = item.Id,
                    text = item.Name
                };
                menus.Add(cat);

                if (item.BusinessCategories != null && item.BusinessCategories.Count > 0)
                {
                    if (cat.children == null)
                        cat.children = new List<TreeData>();
                    _addChildrend(cat, item.BusinessCategories);

                }

            }
            return Json(menus, JsonRequestBehavior.AllowGet);
        }