Beispiel #1
0
        public List <CategoryViewModel> GetGoodsCategoryInfo()
        {
            var categories     = dao.GetLevel1Categories();
            var goodsCategory  = dao.GetGoodsCategoryInfo();
            var categoriesList = new List <CategoryViewModel>();

            foreach (DataRow row in categories.Rows)
            {
                var       goodsList = new List <GoodsViewModel>();
                DataRow[] goodsRows = goodsCategory.Select("categoryid=" + row["CategoryID"]);
                foreach (DataRow goodsRow in goodsRows)
                {
                    var goods = new GoodsViewModel()
                    {
                        GoodsID   = (int)goodsRow["goodsid"],
                        ShortName = (string)goodsRow["shortname"],
                    };
                    goodsList.Add(goods);
                }

                var category = new CategoryViewModel()
                {
                    CategoryID   = (int)row["CategoryID"],
                    CategoryName = (string)row["CategoryName"],
                    GoodsList    = goodsList
                };
                categoriesList.Add(category);
            }
            return(categoriesList);
        }