/// <summary> /// 获取指定Id分类信息 /// </summary> 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> /// 获取指定Rename分类信息 /// </summary> 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> /// 获得格式化后的分类列表 /// </summary> 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> 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> 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(this HtmlHelper helper, CategoryModel category) { return WebUtils.GetCateUrl(category); }
/// <summary> /// 分类链接url /// </summary> public static string GetCateUrl(CategoryModel category) { return GetCurrentLangPath()+ (!string.IsNullOrWhiteSpace(category.ReName) ? "/"+category.ReName + "/" : "/cate/" + category.CateId); }