コード例 #1
0
        public static WMGoodCategories Get(string id)
        {
            WMGoodCategories category = null;

            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    category = (
                        from gc in context.GoodCategories
                        where gc.Id.Equals(id)
                        select new WMGoodCategories
                    {
                        Id = gc.Id,
                        ParentId = gc.ParentId,
                        ParentName = (!gc.ParentId.Equals("root") ? context.GoodCategories.Where(g => g.Id.Equals(gc.ParentId)).Select(g => g.Name).FirstOrDefault() : "root"),
                        Name = gc.Name,
                        Level = gc.Level,
                        Sort = gc.Sort
                    }
                        ).FirstOrDefault();
                }
            }

            return(category);
        }
コード例 #2
0
        public static List <WMGoodCategories> GetTree(string id)
        {
            List <WMGoodCategories> list = new List <WMGoodCategories>();

            if (!General.IsNullable(id))
            {
                WMGoodCategories model = Get(id);

                if (model != null)
                {
                    list.Add(model);

                    while (!model.ParentId.Equals("root"))
                    {
                        model = Get(model.ParentId);
                        list.Insert(0, model);
                    }
                }
            }

            return(list);
        }