[C#] 纯文本查看 复制代码
/// <summary>
/// 获取子菜单列表,根据角色id,与主菜单id
/// </summary>
/// <param name="roleId"></param>
/// <param name="parentId"></param>
/// <returns></returns>
public List<Sys_MenuInfo> GetSonMenuByRoleId(int roleId, int parentId)
{
// 获取角色下的所有菜单信息
var roleMenuList = new Sys_MenuInRoleBLL().GetList("MenuID", string.Format("RoleID = {0}", roleId), "");
if (roleMenuList != null && roleMenuList.Any())
{
// 获取所有子菜单列表
var sonRoleMenuList = roleMenuList.Where(r => r.levelFlag == 0);
if (sonRoleMenuList != null && sonRoleMenuList.Any())
{
// 获取所有子菜单ids
var menuIds = sonRoleMenuList.Select(m => m.MenuID);
// 获取所有主菜单下存在的角色菜单信息
var menuList = GetList("", string.Format("MenuID in ({0}) AND ParentID = {1}", string.Join(",", menuIds), parentId), "");
// 返回信息
if (menuList == null) { return new List<Sys_MenuInfo>(); }
return menuList;
}
}
return new List<Sys_MenuInfo>();
}