Exemple #1
0
        public static List <ProCat> ProCatTree_Create(List <ProductEntity> proentities)
        {
            var pros = new List <ProCat>(95);

            foreach (var p in proentities)
            {
                if (p.pc_path.Length == 2)   // 第一层级
                {
                    var pc = new ProCat(p.pc_path, p.pc_name);
                    pros.Add(pc);
                }
                else if (p.pc_path.Length == 4)  // 第二层级
                {
                    var pc     = new ProCat(p.pc_path, p.pc_name, true);
                    var prefix = p.pc_path.Substring(0, 2);
                    for (int i = pros.Count - 1; i > -1; i--)
                    {
                        if (pros[i].code == prefix)
                        {
                            pros[i].pros.Add(pc);
                            break;
                        }
                    }
                }
            }
            return(pros);
        }
Exemple #2
0
        public IActionResult AddCategory(int id, int Cid)
        {
            ProCat z = new ProCat {
                ProductId  = id,
                CategoryId = Cid
            };

            _context.product_category.Add(z);
            _context.SaveChanges();
            return(RedirectToAction("ShowProducts"));
        }