public ActionResult ClearTree(string category_type) { return(RunActionWhenLogin((loginuser) => { if (!ValidateHelper.IsPlumpString(category_type)) { return GetJsonRes("节点类型未指定"); } var bll = new CategoryBll(); var list = bll.GetCategoryByType(category_type); var errlist = bll.AnalysisTreeStructureAndGetErrorNodesList(list); if (ValidateHelper.IsPlumpList(errlist)) { string res = bll.DeleteSingleNodeByIDS(errlist.Select(x => x.CategoryID).ToArray()); return GetJsonRes(res); } else { return GetJsonRes("没有找到需要清理的节点"); } })); }
/// <summary> /// 分类管理 /// </summary> /// <returns></returns> public ActionResult CategoryManage(string type) { return(RunActionWhenLogin((loginuser) => { var model = new CategoryManageViewModel(); //读取树的数据 var bll = new CategoryBll(); { //加载所有类型 model.TypesList = bll.GetTop(); var cookie_key = "deft_category"; if (!ValidateHelper.IsPlumpString(type)) { type = CookieHelper.GetCookie(this.X.context, cookie_key); } if (!ValidateHelper.IsPlumpString(type) && ValidateHelper.IsPlumpList(model.TypesList)) { type = model.TypesList[0]; } if (!ValidateHelper.IsPlumpString(type)) { return Content("未指定类型"); } //3个月过期 CookieHelper.SetCookie(this.X.context, cookie_key, type, expires_minutes: 60 * 24 * 30); model.CategoryType = type; } var list = bll.GetCategoryByType(type); model.HasNodes = ValidateHelper.IsPlumpList(list); if (model.HasNodes) { //错误节点 model.ErrList = bll.AnalysisTreeStructureAndGetErrorNodesList(list); if (!ValidateHelper.IsPlumpList(model.ErrList)) { list = list.OrderByDescending(x => x.OrderNum).ToList(); //没有错误节点,返回Ztree的json var data = list.Select(x => new { id = x.CategoryID, pId = x.CategoryParent, name = x.OrderNum + "-" + x.CategoryName + "-" + x.CategoryDescription, description = x.CategoryDescription, link_url = x.LinkURL, order_num = x.OrderNum, open_in_new_window = x.OpenInNewWindow, icon_class = x.IconClass, image_url = x.CategoryImage }).ToList(); model.Json = JsonHelper.ObjectToJson(data); } } else { return InitTree(type); } ViewData["model"] = model; return View(); }, NoPermissionResult: new GoHomeResult())); }