public ActionResult AddCategory(CategoryModel model)
        {
            if (AdminCategories.GetCateIdByName(model.CategroyName) > 0)
            {
                ModelState.AddModelError("CategroyName", "名称已经存在");
            }

            if (model.ParentCateId != 0 && AdminCategories.GetCategoryById(model.ParentCateId) == null)
            {
                ModelState.AddModelError("ParentCateId", "父分类不存在");
            }

            if (ModelState.IsValid)
            {
                CategoryInfo categoryInfo = new CategoryInfo()
                {
                    DisplayOrder = model.DisplayOrder,
                    Name         = model.CategroyName,
                    ParentId     = model.ParentCateId,
                    PriceRange   = CommonHelper.StringArrayToString(CommonHelper.RemoveArrayItem(StringHelper.SplitString(CommonHelper.TBBRTrim(model.PriceRange).Replace(",", ","))))
                };

                AdminCategories.CreateCategory(categoryInfo);
                AddAdminOperateLog("添加分类", "添加分类,分类为:" + model.CategroyName);
                return(PromptView("分类添加成功"));
            }

            Load();
            return(View(model));
        }
        public ActionResult EditCategory(CategoryModel model, int cateId = -1)
        {
            CategoryInfo categoryInfo = AdminCategories.GetCategoryById(cateId);

            if (categoryInfo == null)
            {
                return(PromptView("此分类不存在"));
            }

            int cateId2 = AdminCategories.GetCateIdByName(model.CategroyName);

            if (cateId2 > 0 && cateId2 != cateId)
            {
                ModelState.AddModelError("CategroyName", "名称已经存在");
            }

            if (model.ParentCateId == categoryInfo.CateId)
            {
                ModelState.AddModelError("ParentCateId", "不能将自己作为父分类");
            }

            if (model.ParentCateId != 0 && AdminCategories.GetCategoryById(model.ParentCateId) == null)
            {
                ModelState.AddModelError("ParentCateId", "父分类不存在");
            }

            if (model.ParentCateId != 0 && AdminCategories.GetChildCategoryList(categoryInfo.CateId, categoryInfo.Layer, true).Exists(x => x.CateId == model.ParentCateId))
            {
                ModelState.AddModelError("ParentCateId", "不能将分类调整到自己的子分类下");
            }

            if (ModelState.IsValid)
            {
                int oldParentId = categoryInfo.ParentId;

                categoryInfo.DisplayOrder = model.DisplayOrder;
                categoryInfo.Name         = model.CategroyName;
                categoryInfo.ParentId     = model.ParentCateId;
                categoryInfo.PriceRange   = CommonHelper.StringArrayToString(CommonHelper.RemoveArrayItem(StringHelper.SplitString(CommonHelper.TBBRTrim(model.PriceRange).Replace(",", ","))));

                AdminCategories.UpdateCategory(categoryInfo, oldParentId);
                AddAdminOperateLog("修改分类", "修改分类,分类ID为:" + cateId);
                return(PromptView("商品修改成功"));
            }

            Load();
            return(View(model));
        }