public ActionResult New(AddEditCategoryForm model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("~/Views/Shared/AddNewPopup.cshtml", model).WithWarning("Some fields are invalid!"));
            }

            var category = new Category(model.Name);

            category.ParentCategoryID = Convert.ToInt32(model.CategoryID);
            category.ImagePath        = model.ImagePath;
            category.DisplayOrder     = model.DisplayOrder;
            category.Published        = model.Published;

            _context.Categories.Add(category);

            _context.SaveChanges();

            return(Json(new { success = true }));
        }
        public ActionResult Edit(AddEditCategoryForm model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("~/Views/Shared/EditPopup.cshtml", model));
            }

            var category = _context.Categories.SingleOrDefault(i => i.ID == model.ID);

            if (category == null)
            {
                return(JsonError("Cannot find the product specified."));
            }

            category.ParentCategoryID = Convert.ToInt32(model.CategoryID);
            category.ImagePath        = model.ImagePath;
            category.DisplayOrder     = model.DisplayOrder;
            category.Published        = model.Published;

            _context.SaveChanges();

            return(Json(new { success = true }));
        }