// GET: tb_goodssort/Edit/5
        public ActionResult Edit(int?id)
        {
            Sidebar();
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tb_goodssort model  = db.tb_goodssort.Find(id);
            var          models = new tb_goodssortview
            {
                ID        = model.ID,
                SortName  = model.SortName,
                Grade     = model.Grade,
                ParentID  = model.ParentID,
                SortIndex = model.SortIndex,
            };

            models.ImagePath.Images = model.ImagePath?.Split(',') ?? new string[0];
            ViewBag.ParentID        = new SelectList(db.tb_goodssort.Where(s => s.Grade == 1 && s.ParentID != s.ID), "ID", "SortName", models.ParentID);
            ViewBag.Grade           = new SelectList(db.GoodsSortGrade.OrderBy(s => s.Index), "ID", "Name", models.Grade);

            if (models == null)
            {
                return(HttpNotFound());
            }
            return(View(models));
        }
        // GET: tb_goodssort/Create
        public ActionResult Create()
        {
            ViewBag.ParentID = new SelectList(db.tb_goodssort.Where(s => s.Grade == 1 && s.ParentID != s.ID), "ID", "SortName");
            ViewBag.Grade    = new SelectList(db.GoodsSortGrade.OrderBy(s => s.Index), "ID", "Name");
            Sidebar();
            var model = new tb_goodssortview();

            return(View(model));
        }
        public ActionResult Edit(tb_goodssortview tb_goodssort)
        {
            if (ModelState.IsValid)
            {
                var t = db.tb_goodssort.FirstOrDefault(s => s.ID == tb_goodssort.ID);
                t.ID       = tb_goodssort.ID;
                t.SortName = tb_goodssort.SortName;
                t.Grade    = tb_goodssort.Grade;
                //t.EnterpriseID = AccontData.EnterpriseID;
                t.ParentID  = tb_goodssort.Grade == 1 ? 0 : tb_goodssort.ParentID;
                t.SortIndex = tb_goodssort.SortIndex;
                t.ImagePath = string.Join(",", tb_goodssort.ImagePath.Images);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(tb_goodssort));
        }
        public ActionResult Create(tb_goodssortview tb_goodssort)
        {
            if (ModelState.IsValid)
            {
                var model = new tb_goodssort
                {
                    SortName  = tb_goodssort.SortName,
                    Grade     = tb_goodssort.Grade,
                    ImagePath = string.Join(",", tb_goodssort.ImagePath.Images),
                    ParentID  = tb_goodssort.Grade == 1 ? 0 : tb_goodssort.ParentID,
                    SortIndex = tb_goodssort.SortIndex
                };
                db.tb_goodssort.Add(model);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tb_goodssort));
        }