public List <FunctionModel> GetFunctionByUserIdAndMenuId(int userId, int menuId) { string cachekey = userId + "-" + menuId; var list = CacheManager.CreateCache().Get <List <FunctionModel> >(cachekey); if (list != null && list.Count > 0) { return(list); } list = new List <FunctionModel>(20); if (CommonAction.IsSysAdmin(userId))//如果是管理员 获取菜单所有的功能 { var builtin = BuiltinRoles.All.Select(n => new FunctionModel { FunctionKey = n, FunctionName = n }); list.Add(new FunctionModel { FunctionKey = "$ADMIN", FunctionName = "$ADMIN" }); list.AddRange(builtin); list.AddRange(RoleNavigationFunctionDbAction.GetFunctionsByNavigationId(menuId)); } else { var roles = UserRolesDbAction.GetUserRolses(userId); roles.ForEach(n => { if (BuiltinRoles.All.Contains(n.RoleName)) { list.Add(new FunctionModel { FunctionKey = n.RoleName, FunctionName = n.RoleName }); } }); //角色分配的功能 var roleIds = roles.Select(p => p.RoleId).ToList(); ICollection <FunctionModel> funcList = RoleNavigationFunctionDbAction.GetFunctionsByRoleIdsAndNavigationId(roleIds, menuId); ICollection <FunctionModel> userFuncList = UserNavigationFunctionDbAction.GetFunctionsByUserIdsAndNavigationId(new List <int> { userId }, menuId); list.AddRange(funcList); list.AddRange(userFuncList.Except(funcList).ToList()); } CacheManager.CreateCache().Add(cachekey, list); return(list); }
public List <MenuResponse> GetMenusByChkUserId(int userId, int appId) { var menus = UserNavigationFunctionDbAction.GetMenuFunctions(new List <int>() { userId }, appId); List <MenuResponse> topMenus = new List <MenuResponse>(); foreach (var fun in menus) { GetTopMenu(fun, menus, topMenus); } foreach (var menu in topMenus) { SetChildren(menus, menu); } return(topMenus); }
public List <MenuResponse> GetMenuByUserId(int userId, int appId, out List <RoleResponse> roles) { roles = UserManagerDb.GetRolesByUserId(userId); List <MenuResponse> menus = null; if (CommonAction.IsSysAdmin(userId)) { menus = RoleNavigationFunctionDbAction.GetAdminMenu(appId); } else { menus = new List <MenuResponse>(); menus.AddRange(RoleNavigationFunctionDbAction.GetMenuFunctions(roles.Select(n => n.RoleId).ToList(), appId)); menus.AddRange(UserNavigationFunctionDbAction.GetMenuFunctions(new List <int> { userId }, appId)); menus = menus.Where((i, j) => menus.FindIndex(f => f.Id == i.Id) == j).ToList(); } //var menus = CommonAction.IsSysAdmin(userId) // ? RoleNavigationFunctionDbAction.GetAdminMenu(appId) // : RoleNavigationFunctionDbAction.GetMenuFunctions(roles.Select(n => n.RoleId).ToList(), appId); var topMenus = new List <MenuResponse>(); foreach (var fun in menus) { GetTopMenu(fun, menus, topMenus); } foreach (var menu in topMenus) { SetChildren(menus, menu); } return(topMenus); }