/// <summary> /// 递归获取友情链接集合结构 /// </summary> /// <param name="root"></param> /// <param name="allNavList"></param> private void GetSubFriendlyLinkCategoryListByRecursion(EFriendlyLinkCategory root, List<EFriendlyLinkCategory> list, List<EFriendlyLinkCategory> allNavList) { //获取下一级菜单 var children = allNavList.Where(p => p.FriendlyLinkCategoryParentId == root.Id).ToList(); if (children.Count > 0) { list.AddRange(children); foreach (var sub in children) { GetSubFriendlyLinkCategoryListByRecursion(sub, list, allNavList); } } }
/// <summary> /// 递归获取菜单树结构 /// </summary> /// <param name="root"></param> /// <param name="allFriendlyLinkCategorys"></param> private void GetFriendlyLinkCategoryTreeByRecursion(EFriendlyLinkCategory root, IList<EFriendlyLinkCategory> allFriendlyLinkCategorys) { //获取下一级菜单 var children = allFriendlyLinkCategorys.Where(p => p.FriendlyLinkCategoryParentId == root.Id).ToList(); if (children.Count > 0) { root.Children = children; foreach (var sub in root.Children) { GetFriendlyLinkCategoryTreeByRecursion(sub, allFriendlyLinkCategorys); } } }
public void SaveFriendlyLinkCategory(EFriendlyLinkCategory friendlyLinkCategory) { _rep.Save(friendlyLinkCategory, p => p.Id == friendlyLinkCategory.Id); }
/// <summary> /// 递归获取友情链接集合结构 /// </summary> /// <param name="friendlyLinkCategoryId"></param> public IList<EFriendlyLinkCategory> GetSubFriendlyLinkCategoryList(int? friendlyLinkCategoryId) { List<EFriendlyLinkCategory> list = new List<EFriendlyLinkCategory>(); if (friendlyLinkCategoryId.HasValue) { EFriendlyLinkCategory root = _rep.Get<EFriendlyLinkCategory>(p => p.Id == friendlyLinkCategoryId); GetSubFriendlyLinkCategoryListByRecursion(root, list); return list; } else { EFriendlyLinkCategory root = new EFriendlyLinkCategory() { Id = friendlyLinkCategoryId ?? 0, FriendlyLinkCategoryName = "友情链接" }; IList<EFriendlyLinkCategory> allNavList = _rep.GetAll<EFriendlyLinkCategory>(p => p.Id.Desc()); GetSubFriendlyLinkCategoryListByRecursion(root, allNavList.ToList()); return list; } }
/// <summary> /// 获取友情链接树结构 /// </summary> /// <returns></returns> public EFriendlyLinkCategory GetFriendlyLinkCategoryTree(int? friendlyLinkCategoryId) { EFriendlyLinkCategory root = null; if (friendlyLinkCategoryId.HasValue) { root = _rep.Get<EFriendlyLinkCategory>(p => p.Id == friendlyLinkCategoryId); root.FriendlyLinkCategoryName = "根分类"; } else { root = new EFriendlyLinkCategory() { Id = 0, FriendlyLinkCategoryName = "站点" }; } IList<EFriendlyLinkCategory> allFriendlyLinkCategorys = _rep.GetAll<EFriendlyLinkCategory>(p => p.FriendlyLinkCategoryOrderId.Asc()); GetFriendlyLinkCategoryTreeByRecursion(root, allFriendlyLinkCategorys); return root; }
public void AddFriendlyLinkCategory(EFriendlyLinkCategory friendlyLinkCategory) { using (var dmTrans = _rep.GetTransaction()) { try { var tran = dmTrans.BeginTransaction(); _rep.Add(friendlyLinkCategory, tran); dmTrans.Commit(); } catch { dmTrans.Rollback(); throw; } } }