示例#1
0
        public ActionResult Category()
        {
            CategoryFunc    cf     = new CategoryFunc();
            List <Category> ctList = new List <Category>();

            ctList        = cf.GetCategoryAndSort();
            ViewBag.Title = "栏目管理";
            return(View(ctList));
        }
示例#2
0
        public ActionResult DeleteCategoryConfirmed(int id)
        {
            ViewBag.Title = "删除栏目";
            CategoryFunc cf    = new CategoryFunc();
            Response     _resp = cf.Delete(id);

            if (_resp.Code == 1)//无法删除
            {
                ModelState.AddModelError("ParentID", _resp.Message);
                Category cate = cf.Find(id);
                return(View(cate));
            }
            else//删除成功
            {
                return(RedirectToAction("Category", "Admin"));
            }
        }
示例#3
0
 public ActionResult CreateCategory(CategoryAddViewModel newCateVM)
 {
     if (ModelState.IsValid)
     {
         CategoryFunc cf      = new CategoryFunc();
         Category     newCate = new Category();
         newCate.Name        = newCateVM.Name;
         newCate.ParentID    = newCateVM.ParentID;
         newCate.Description = newCateVM.Description;
         newCate.Order       = newCateVM.Order;
         newCate.Level       = newCateVM.Level;
         cf.Add(newCate);
         return(RedirectToAction("Category", "Admin"));
     }
     else
     {
         return(View(newCateVM));
     }
 }
示例#4
0
        public ActionResult DeleteCategory(int?id)
        {
            ViewBag.Title = "删除栏目";
            CategoryFunc cf    = new CategoryFunc();
            Category     _cate = new Category();

            if (id == null || id.GetType() != typeof(int))
            {
                return(RedirectToAction("Category", "Admin"));
            }
            else if (cf.Find((int)id) == null)
            {
                return(RedirectToAction("Category", "Admin"));
            }
            else
            {
                _cate = cf.Find((int)id);
                return(View(_cate));
            }
        }
示例#5
0
        public ActionResult CreateCategory(int?id)
        {
            Category             _pcate   = new Category();
            CategoryAddViewModel _newCate = new CategoryAddViewModel();
            CategoryFunc         cf       = new CategoryFunc();
            int pid = 0;

            //当参数id为空时,表示创建根栏目,父栏目id设为0
            if (id == null)
            {
                pid = 0;
            }
            //当参数id不为整数时,强制设定父栏目id为0
            else if (id.GetType() != typeof(int))
            {
                pid = 0;
            }
            else
            {
                pid = (int)id;
            }
            if (cf.Find(pid) == null)
            {
                _newCate.PName    = "无";
                _newCate.ParentID = 0;
                _newCate.Order    = 50;
                _newCate.Level    = 0;
            }
            else
            {
                _pcate            = cf.Find(pid);
                _newCate.PName    = _pcate.Name;
                _newCate.ParentID = _pcate.CategoryID;
                _newCate.Order    = 50;
                _newCate.Level    = _pcate.Level + 1;
            }
            ViewBag.Title = "添加栏目";
            return(View(_newCate));
        }
示例#6
0
        public ActionResult ModifyCategory(CategoryAddViewModel cateVM, int categoryID)
        {
            ViewBag.Title = "修改栏目";
            CategoryFunc cf    = new CategoryFunc();
            Category     _cate = new Category();

            if (ModelState.IsValid)
            {
                _cate.CategoryID  = categoryID;
                _cate.Name        = cateVM.Name;
                _cate.ParentID    = cateVM.ParentID;
                _cate.Description = cateVM.Description;
                _cate.Order       = cateVM.Order;
                _cate.Level       = cateVM.Level;
                cf.Modify(_cate);
                return(RedirectToAction("Category", "Admin"));
            }
            else
            {
                ViewBag.CategoryID = categoryID;
                return(View(cateVM));
            }
        }
示例#7
0
        public ActionResult ModifyCategory(int?id)
        {
            ViewBag.Title = "修改栏目";
            CategoryFunc cf    = new CategoryFunc();
            Category     _cate = new Category();

            if (id == null || id.GetType() != typeof(int))
            {
                return(RedirectToAction("Category", "Admin"));
            }
            else if (cf.Find((int)id) == null)
            {
                return(RedirectToAction("Category", "Admin"));
            }
            else
            {
                _cate = cf.Find((int)id);
                CategoryAddViewModel _cateVM = new CategoryAddViewModel();
                if (_cate.ParentID == 0)
                {
                    _cateVM.PName = "无";
                }
                else
                {
                    _cateVM.PName = cf.Find(_cate.ParentID).Name;
                }

                _cateVM.ParentID    = _cate.ParentID;
                _cateVM.Name        = _cate.Name;
                _cateVM.Description = _cate.Description;
                _cateVM.Order       = _cate.Order;
                _cateVM.Level       = _cate.Level;
                ViewBag.CategoryID  = _cate.CategoryID;
                return(View(_cateVM));
            }
        }