// 根据角色ID获取链接 private static List <string> GetModulesInRole(Guid roleID) { List <string> urls = new List <string>(); List <SPhone_Module> lst = null; using (var db = DCHelper.SPhoneContext()) { List <Guid> mids = db.SPhone_RoleModule.Where(rm => rm.RoleID == roleID).Select(rm => rm.ModuleID).ToList(); lst = db.SPhone_Module.ToList(); mids.ForEach(id => { SPhone_Module module = lst.Find(m => m.ModuleID == id); if (module != null) { urls.Add(module.ModuleUrl); } }); } return(urls); }
// 获取菜单树的值 public static string GetTreeValue(Dictionary <string, int> selectedIDs) { List <SPhone_Module> modules = new List <SPhone_Module>(); using (var db = DCHelper.SPhoneContext()) { modules = db.SPhone_Module.ToList(); } SPhone_Module root = new SPhone_Module() { ModuleID = Guid.Empty, ModuleName = "应用模块", ParentModuleID = Guid.Empty }; if (root == null) { return(string.Empty); } JSONTree tree = new JSONTree(root.ModuleID.ToString(), root.ModuleName); SPhone_Module parent = null; foreach (SPhone_Module item in modules.OrderBy(item => item.CreateTime)) { parent = modules.Find(o => o.ModuleID == item.ParentModuleID); if (parent == null) { parent = root; } int checkedSign = 0; string id = item.ModuleID.ToString(); if (selectedIDs.ContainsKey(id)) { checkedSign = selectedIDs[id]; } bool showCheckbox = !item.ParentModuleID.Equals(Guid.Empty); tree.Root.AppendNode(item.ParentModuleID.ToString(), id, item.ModuleName , id, true, showCheckbox, checkedSign); } return(tree.ToString()); }