public static IList <FunctionGroup> GetFunctionsByRoleId(int roleId) { IList <FunctionGroup> funcList = new List <FunctionGroup>(); IList <IRole> roleList = RoleFactory.Instance.GetAll(); IRole role = null; foreach (IRole rl in roleList) { if (rl.Id == roleId) { role = rl; } } foreach (FunctionGroup funcGroup in RBACContext.Functions) { FunctionGroup funcg = new FunctionGroup(); funcg.Name = funcGroup.Name; foreach (Function func in funcGroup.Functions) { if (role.FunctionIds.Contains(func.Id)) { funcg.Functions.Add(func); } } if (funcg.Functions.Count > 0) { funcList.Add(funcg); } } return(funcList); }
private static void LoadFunctions(XmlNode node, RBACContext rbac) { foreach (System.Xml.XmlNode groupNode in node.ChildNodes) { if (groupNode.NodeType != XmlNodeType.Element || groupNode.Name.ToLower() != "group") { continue; } FunctionGroup group = new FunctionGroup() { Name = groupNode.GetAttribute("name", null) }; foreach (System.Xml.XmlNode funcNode in groupNode.ChildNodes) { if (funcNode.NodeType != XmlNodeType.Element || funcNode.Name.ToLower() != "function") { continue; } Function func = new Function() { Id = funcNode.GetAttribute("ID", null), Name = funcNode.GetAttribute("name", null) }; group.Functions.Add(func); } rbac.Functions.Add(group); } }