Exemplo n.º 1
0
        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));
        }