예제 #1
0
        public ActionResult Create(ProductCategory productcategory, string nextStep)
        {
            this.ValidateRequest = false;
            if (ModelState.IsValid)
            {
                db.ProductCategories.Add(productcategory);
                db.SaveChanges();
                return Redirect(nextStep);
            }

            ViewBag.ParentId = new SelectList(db.ProductCategories, "Id", "Name", productcategory.ParentId);
            CreateFrame(title);
            return View(productcategory);
        }
예제 #2
0
 //
 // GET: /AdminProductCategory/Create
 public ActionResult Create(int? id)
 {
     CreateFrame(title);
     var parent = db.ProductCategories.Find(id);
     ViewBag.ParentId = new SelectList(db.ProductCategories, "Id", "Name", id);
     var category = new ProductCategory();
     category.Active = true;
     /*
     if (parent != null)
     {
         category.Url = parent.Url + "/";
     }
     */
     return View(category);
 }
예제 #3
0
 public ActionResult Edit(ProductCategory productcategory, string nextStep)
 {
     this.ValidateRequest = false;
     if (ModelState.IsValid)
     {
         db.Entry(productcategory).State = EntityState.Modified;
         db.SaveChanges();
         return Redirect(nextStep);
     }
     ViewBag.ParentId = new SelectList(db.ProductCategories, "Id", "Name", productcategory.ParentId);
     return View(productcategory);
 }
예제 #4
0
파일: Product.cs 프로젝트: vuuvv/vcms
        public static Node<ProductCategory> CreateTree(ProductCategory[] categories, ProductCategory current)
        {
            Dictionary<int, Node<ProductCategory>> lookup = new Dictionary<int, Node<ProductCategory>>();
            Dictionary<int?, List<Node<ProductCategory>>> children = new Dictionary<int?, List<Node<ProductCategory>>>();

            List<Node<ProductCategory>> roots = new List<Node<ProductCategory>>();

            foreach (var category in categories)
            {
                Node<ProductCategory> node = new Node<ProductCategory>();
                node.Data = category;
                node.Children = new List<Node<ProductCategory>>();

                lookup.Add(category.Id, node);

                if (category.ParentId != null)
                {
                    if (!children.ContainsKey(category.ParentId))
                    {
                        children[category.ParentId] = new List<Node<ProductCategory>>();
                    }
                    children[category.ParentId].Add(node);
                }

                if (category.ParentId == null)
                {
                    node.Parent = null;
                    roots.Add(node);
                }
            }

            foreach (var node in lookup.Values)
            {
                var category = node.Data;
                Node<ProductCategory> parent = null;
                if (category.ParentId != null)
                {
                    parent = lookup[(int)category.ParentId];
                }
                node.Parent = parent;
                if (children.ContainsKey(category.Id))
                {
                    node.Children = children[category.Id];
                }
            }

            return lookup[current.Id];
        }