/// <summary> /// 获取指定Rename分类信息 /// </summary> /// <param name="cid"></param> /// <returns></returns> public CategoryModel GetCategoryByReName(string rename) { CategoryModel category = new CategoryModel(); try { List<CategoryModel> lst = GetCategoryList(); category = lst.Find((CategoryModel p) => { return p.ReName == rename; }); return category; } catch (Exception) { return null; } }
/// <summary> /// 获取指定Id分类信息 /// </summary> /// <param name="cid"></param> /// <returns></returns> public CategoryModel GetCategoryByID(int cid) { CategoryModel category = new CategoryModel(); try { List<CategoryModel> lst = GetCategoryList(); category = lst.Find((CategoryModel p) => { return p.CateId == cid.ToString(); }); return category; } catch (Exception) { return null; } }
/// <summary> /// 刷新catelist,更新subcuont,path字段 /// </summary> public List<CategoryModel> RefreshCateList(List<CategoryModel> lst) { List<CategoryModel> newlst = new List<CategoryModel>(); foreach (CategoryModel c in lst) { CategoryModel category = new CategoryModel(); category = c; category.Path = GetCategoryPath(lst, category); category.SubCount = GetSubCount(lst, category.CateId).ToString(); newlst.Add(category); } return newlst; }
public ActionResult AdminCategorySort(string ids) { Category clsCategory = new Category(); List<CategoryModel> orderlst = new List<CategoryModel>(); List<CategoryModel> newlst = new List<CategoryModel>(); string[] arrId = ids.Trim(',').Split(','); for (int i = 0; i < arrId.Length; i++) { int orderid = i + 1; CategoryModel category = new CategoryModel(); category = clsCategory.GetCategoryByID(Utils.StrToInt(arrId[i])); category.OrderId = orderid.ToString(); orderlst.Add(category); } GetNewCategoryList(orderlst, ref newlst, "0"); SaveCateInfo(newlst); string re = ""; var lst = clsCategory.getFCategoryList(" -- "); foreach (CategoryModel c in lst) { string rootClass = c.ParentId == "0" ? " class=\"cl_root\"" : ""; re += "<li id=\"" + c.CateId + "\"" + rootClass + ">" + c.CateName + " (" + c.CateId + ")</li>"; } return Content(re, "text/html;charset=UTF-8"); }
public ActionResult AdminCategoryEdit(CategoryModel model) { Category clsCategory = new Category(); List<CategoryModel> catelist = clsCategory.getFCategoryList(); List<CategoryModel> newlst = new List<CategoryModel>(); List<CategoryModel> newlst2 = new List<CategoryModel>(); CategoryModel category = new CategoryModel(); category.CateId = model.CateId; category.CateName = model.CateName; category.IsIndex = model.IsIndex; category.IsNav = model.IsNav; category.ListNum = string.IsNullOrWhiteSpace(model.ListNum) ? "0" : model.ListNum; category.ParentId = model.ParentId; category.ReName = string.IsNullOrWhiteSpace(model.ReName) ? "" : model.ReName; category.CustomView = string.IsNullOrWhiteSpace(model.CustomView) ? "" : model.CustomView; category.ReplyPermit = model.ReplyPermit; category.Status = model.Status; category.Type = model.Type; category.OrderId = (catelist.Count() + 1).ToString(); category.SubCount = "0"; category.Path = "0"; bool isPathChange = false; foreach (CategoryModel c in catelist) { if (category.CateId == c.CateId) { if (category.ParentId == c.ParentId) { category.OrderId = c.OrderId; category.SubCount = c.SubCount; category.Path = c.Path; } newlst.Add(category); } else newlst.Add(c); } if (category.Path == "0") { isPathChange = true; //刷新subcount,path值 newlst = RefreshCateList(newlst); //重置顺序orderid GetNewCategoryList(newlst, ref newlst2, "0"); } else { newlst2 = newlst; } //保存为json SaveCateInfo(newlst2); //分类层级关系改变时更新文章表里path信息 if (isPathChange) { CategoryModel newcategory = clsCategory.GetCategoryByID(Utils.StrToInt(model.CateId)); // clsCategory.BatchUpdateArticlePath(Utils.StrToInt(model.CateId), newcategory.Path); } return Content(res.AddedSuccessfully + " <a href=\"/QAAdmin/admin/AdminCategorySort\">" + res.View + "</a>", "text/html;charset=UTF-8"); }
public ActionResult AdminCategoryAdd(CategoryModel model) { Category clsCategory = new Category(); List<CategoryModel> newlst = new List<CategoryModel>(); List<CategoryModel> catelist = clsCategory.getFCategoryList(); CategoryModel category = new CategoryModel(); category.CateId = (clsCategory.GetMaxCategoryID() + 1).ToString(); category.CateName = model.CateName; category.IsIndex = model.IsIndex; category.IsNav = model.IsNav; category.ListNum = string.IsNullOrWhiteSpace(model.ListNum) ? "0" : model.ListNum; category.ParentId = model.ParentId; category.ReName = string.IsNullOrWhiteSpace(model.ReName) ? "" : model.ReName; category.CustomView = string.IsNullOrWhiteSpace(model.CustomView) ? "" : model.CustomView; category.ReplyPermit = model.ReplyPermit; category.Status = model.Status; category.Type = model.Type; category.OrderId = (catelist.Count() + 1).ToString(); category.SubCount = "0"; category.Path = category.CateId; if (category.ParentId == "0") { catelist.Add(category); newlst = catelist; } else { catelist.Add(category); //刷新subcount,path值 catelist = RefreshCateList(catelist); //重置顺序orderid GetNewCategoryList(catelist, ref newlst, "0"); } //保存为json SaveCateInfo(newlst); return Content(res.AddedSuccessfully + " <a href=\"/QAAdmin/admin/AdminCategorySort\">" + res.View + "</a>", "text/html;charset=UTF-8"); }
/// <summary> /// 新增分类 /// </summary> public ActionResult AdminCategoryAdd(int id) { Category clsCategory = new Category(); ViewBag.CateId = id; ViewBag.CateName = id > 0 ? clsCategory.GetCategoryByID(id).CateName : ""; ViewData["Type"] = new SelectList(WebUtils.GetTypeList(), "TypeId", "TypeName", 1); CategoryModel category = new CategoryModel(); category.ParentId = id.ToString(); if (id > 0) category.Type = clsCategory.GetCategoryByID(id).Type; return View(category); }
private string GetCurrentCategoryUrl(CategoryModel category) { return "," + category.CateId; }
/// <summary> /// 计算当前分类的path /// </summary> private string GetCategoryPath(List<CategoryModel> lst, CategoryModel category) { CategoryModel c = category; string path = GetCurrentCategoryUrl(c); while (c.ParentId != "0") { foreach (CategoryModel cc in lst) { if (cc.CateId == c.ParentId) { path = GetCurrentCategoryUrl(cc) + path; c = cc; continue; } } } return path.Trim(','); }
/// <summary> /// 获得格式化后的分类列表 /// </summary> /// <returns></returns> public List<CategoryModel> getFCategoryList(string tids, string cids, string space = "") { string[] arrcid = cids.Split(','); string[] arrtid = tids.Split(','); var list = GetCategories(); if (cids.Trim()!="") list = list.Where(m => arrcid.Contains(m.CateId)); else if (tids.Trim() != "") list = list.Where(m => arrtid.Contains(m.Type)); list = list.OrderBy(m => Utils.StrToInt(m.OrderId)); List<CategoryModel> newlst = new List<CategoryModel>(); CategoryModel category = new CategoryModel(); foreach (CategoryModel c in list) { category = c; category.CateName = (space == "" ? "" : Utils.GetSpace(c.Path.Split(',').Count(), space)) + c.CateName; newlst.Add(c); } return newlst; }
/// <summary> /// 获取分类路径url2(不显示根目录,1级目录显示文字,往后显示为链接) /// </summary> /// <param name="cid"></param> /// <returns></returns> public string GetCategoryPathUrl2(string path) { CategoryModel category = new CategoryModel(); string str = ""; string[] arrpath = path.Split(','); if (arrpath.Count() < 2) return ""; List<CategoryModel> lst = GetCategoryList(); if (arrpath.Count() == 2) { category = lst.Find((CategoryModel p) => { return p.CateId == arrpath[1]; }); str=category.CateName; } else { string newPath = ""; for (int i = 1; i < arrpath.Count(); i++) { newPath += arrpath[i] + ','; } str = GetCategoryPathUrl(newPath.Trim(',')); } return str; }
/// <summary> /// 获取分类路径url /// </summary> /// <param name="cid"></param> /// <returns></returns> public string GetCategoryPathUrl(string path) { string str = ""; CategoryModel category = new CategoryModel(); try { List<CategoryModel> lst = GetCategoryList(); foreach (string s in path.Split(',')) { category = lst.Find((CategoryModel p) => { return p.CateId == s; }); str += "\\ <a href=\"" + WebUtils.GetCateUrl(category) + "\">" + category.CateName + "</a> "; } return str.Trim('\\').Trim(); } catch (Exception) { return ""; } }
/// <summary> /// 分类链接url /// </summary> public static string GetCateUrl(CategoryModel category) { return GetCurrentLangPath() + (!string.IsNullOrWhiteSpace(category.ReName) ? "/" + category.ReName + "/" : "/cate/" + category.CateId); }