Esempio n. 1
0
        /// <summary>
        ///     根据类型获取所有的分类
        /// </summary>
        /// <param name="type"></param>
        public IEnumerable <RelationApiOutput> GetClass(string type, long userId)
        {
            var findType = FindType(type);
            var list     = GetList(r => r.Type == findType.FullName && r.Status == Status.Normal && r.UserId == userId)
                           .OrderBy(r => r.SortOrder)
                           .ToList();
            //attribute
            var relationPropert = findType.GetCustomAttribute <RelationPropertyAttribute>();
            var head            = new RelationApiOutput {
                ChildClass = new List <RelationApiOutput>(),
                Id         = 0
            };
            var loopList = new List <RelationApiOutput> {
                head
            };

            while (loopList.Count > 0)
            {
                var first = loopList[0];
                loopList.Remove(first);
                first.ChildClass = list.Where(r => r.FatherId == first.Id).Select(child => new RelationApiOutput {
                    Name          = child.Name,
                    Icon          = child.Icon,
                    Id            = child.Id,
                    Check         = false,
                    Type          = child.Type.Substring(child.Type.LastIndexOf('.') + 1),
                    UserId        = child.UserId,
                    IsCanAddChild = relationPropert != null ? !relationPropert.IsOnlyRoot : true
                }).ToList();
                loopList.AddRange(first.ChildClass);
            }

            return(head.ChildClass);
        }
Esempio n. 2
0
        /// <summary>
        ///     根据类型获取所有的分类
        /// </summary>
        /// <param name="type"></param>
        public IEnumerable <RelationApiOutput> GetClass(string type)
        {
            var findType = FindType(type);
            var list     = GetList(r => r.Type == findType.FullName && r.Status == Status.Normal).OrderBy(r => r.SortOrder)
                           .ToList();

            var head = new RelationApiOutput {
                ChildClass = new List <RelationApiOutput>(),
                Id         = 0
            };

            var loopList = new List <RelationApiOutput> {
                head
            };

            while (loopList.Count > 0)
            {
                var first = loopList[0];
                loopList.Remove(first);
                first.ChildClass = list.Where(r => r.FatherId == first.Id).Select(child => new RelationApiOutput {
                    Name  = child.Name,
                    Icon  = child.Icon,
                    Id    = child.Id,
                    Check = false,
                    Type  = child.Type.Substring(child.Type.LastIndexOf('.') + 1)
                }).ToList();
                loopList.AddRange(first.ChildClass);
            }

            return(head.ChildClass);
        }
Esempio n. 3
0
        /// <summary>
        ///     根据类型获取所有的父级分类
        /// </summary>
        /// <param name="type"></param>
        public IEnumerable <RelationApiOutput> GetFatherClass(string type)
        {
            var findType = FindType(type);
            var list     = GetList(r => r.Type == findType.FullName && r.Status == Status.Normal && r.FatherId == 0)
                           .OrderBy(r => r.SortOrder).ToList();
            var resultList = new List <RelationApiOutput>();

            foreach (var item in list)
            {
                var keyValue = new RelationApiOutput {
                    Name = item.Name,
                    Icon = item.Icon,
                    Id   = item.Id
                };
                resultList.Add(keyValue);
            }

            return(resultList);
        }