public IActionResult List(string msg) { if (!_session.ChkSession()) { return(RedirectToAction("Login", "Auth")); } if (msg != null) { ModelState.AddModelError("", msg); } IEnumerable <Category> categories = _category.categories.OrderBy(x => x.id); var obj = new CategoryManageViewModel { modelName = "Категории", btnName = "Добавить", categories = categories }; return(View(obj)); }
public IActionResult Manage() { if (_catService.GetAll() != null) { IEnumerable <Category> allCategories = _catService.GetAll().OrderByDescending(x => x.InUse).ThenBy(y => y.CategoryName); int total = allCategories.Count(); int inUse = allCategories.Where(x => x.InUse).Count(); int notInUse = total - inUse; CategoryManageViewModel VM = new CategoryManageViewModel { Total = total, InUse = inUse, NotInUse = notInUse, Categories = allCategories }; return(View(VM)); } else { return(RedirectToAction("NoCategoriesExist", "Category")); } }
/// <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())); }