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)); } }
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)); }
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)); } }
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")); } }