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

            models.ImagePath.Images = model.ImagePath?.Split(',') ?? new string[0];
            ViewBag.ParentID        = new SelectList(db.goodstype.Where(s => s.ParentID != s.ID), "ID", "Name", models.ParentID);

            if (models == null)
            {
                return(HttpNotFound());
            }
            return(View(models));
        }
        // GET: goodstypes/Create
        public ActionResult Create()
        {
            ViewBag.ParentID = new SelectList(db.goodstype.Where(s => s.ParentID != s.ID), "ID", "Name");
            Sidebar();
            var model = new goodstypeview();

            return(View(model));
        }
        public ActionResult Edit(goodstypeview goodstype)
        {
            if (ModelState.IsValid)
            {
                var t = db.goodstype.FirstOrDefault(s => s.ID == goodstype.ID);
                t.ID        = goodstype.ID;
                t.Name      = goodstype.Name;
                t.ParentID  = goodstype.ParentID;
                t.SortIndex = goodstype.SortIndex;
                t.ImagePath = string.Join(",", goodstype.ImagePath.Images);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(goodstype));
        }
        public ActionResult Create(goodstypeview goodstype)
        {
            if (ModelState.IsValid)
            {
                var model = new goodstype
                {
                    Name      = goodstype.Name,
                    ImagePath = string.Join(",", goodstype.ImagePath.Images),
                    ParentID  = goodstype.ParentID,
                    SortIndex = goodstype.SortIndex
                };
                db.goodstype.Add(model);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(goodstype));
        }