public List <MenusOut> GetMenusListOrderBy(long?roleId = null) { //查询相关子表数据 List <SysMenus> dataAll = _sysMenusRepository.GetAllIncluding(x => x.SysMenuActions).ToList(); if (roleId != null) { //获取当前角色的包含的菜单 List <SysRoleToMenuAction> roleToMenuAction = _sysMenuActionRepository.GetMenuActionByRole(Convert.ToInt64(roleId)).ToList(); //设置菜单选中状态 foreach (var item in dataAll) { var data = roleToMenuAction.Where(p => p.MenuID == item.Id); if (!data.Any()) { continue; } item.IsCheck = true; foreach (var subAction in item.SysMenuActions) { var action = roleToMenuAction.Where(p => p.MenuID == item.Id && p.MenuActionID == subAction.Id); if (action.Any()) { subAction.IsCheck = true; } } } } List <SysMenus> resData = _sysMenusRepository.ConvertMenusByChildrenList(dataAll); return(ObjectMapper.Map <List <MenusOut> >(resData)); }
public List <MenusOut> GetMenusListOrderBy(long?roleId = null) { //获取所有菜单模块 List <SysMenus> dataAll = _sysMenusRepository.GetMenusAll().ToList(); if (roleId != null) { //获取当前角色的包含的菜单 List <SysRoleToMenuAction> roleToMenuAction = _sysMenuActionRepository.GetMenuActionByRole(Convert.ToInt64(roleId)).ToList(); //设置菜单选中状态 foreach (var item in dataAll) { var data = roleToMenuAction.Where(p => p.MenuID == item.Id); if (data.Any()) { item.IsCheck = true; foreach (var subAction in item.SysMenuActions) { var action = roleToMenuAction.Where(p => p.MenuID == item.Id && p.MenuActionID == subAction.Id); if (action.Any()) { subAction.IsCheck = true; } } } } } List <SysMenus> resData = _sysMenusRepository.ConvertMenusByOrderByList(dataAll); return(resData.MapTo <List <MenusOut> >()); }