Пример #1
0
        public static ModuleMenu BuildTree(Dictionary <int, ModuleInfo> moduleList)
        {
            if (moduleList != null)
            {
                ModuleMenu baseMenu = new ModuleMenu();
                baseMenu.ModuleId   = moduleList[1].ModuleId;
                baseMenu.ModulePath = moduleList[1].ModulePath;
                baseMenu.ParentId   = 0;

                var childModuleList = moduleList.Values.Where(s => s.ModuleId != 1);

                BuildTree(baseMenu, childModuleList);

                return(baseMenu);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        private static void BuildTree(ModuleMenu menu, IEnumerable <ModuleInfo> moduleList)
        {
            var sonList           = moduleList.Where(s => menu.GetRelationShip(s) == RelationShip.Child);
            var childRelationShip = new RelationShip[] { RelationShip.Child, RelationShip.Childson };

            if (sonList != null)
            {
                menu.ChileMenu = new List <ModuleMenu>();
                foreach (var eachSon in sonList)
                {
                    var newSon   = new ModuleMenu(eachSon);
                    var hisChild = moduleList.Where(s => childRelationShip.Any(e => e == newSon.GetRelationShip(s)));
                    if (hisChild != null)
                    {
                        BuildTree(newSon, hisChild);
                    }
                    menu.ChileMenu.Add(newSon);
                }
                menu.ChileMenu = menu.ChileMenu.OrderBy(s => s.OrderNo).ToList <ModuleMenu>();
            }
        }
Пример #3
0
        public ModuleMenu GetUserMenu(int userId)
        {
            Dictionary <int, Dictionary <int, int> > dic = dal.GetUserRights();
            // dicUserRights 包含该用户所有的 moduleId=>rights
            Dictionary <int, int> dicUserRights = new Dictionary <int, int>();

            if (dic.ContainsKey(userId))
            {
                dicUserRights = dic[userId];
            }
            if (dic.ContainsKey(0))
            {
                foreach (KeyValuePair <int, int> kv in dic[0])
                {
                    if (!dicUserRights.ContainsKey(kv.Key))
                    {
                        dicUserRights.Add(kv.Key, kv.Value);
                    }
                }
            }
            return(ModuleMenu.BuildTree(dal.GetModuleListDict(), dicUserRights.Keys));
        }
Пример #4
0
 public ModuleMenu GetAllMenu()
 {
     return(ModuleMenu.BuildTree(dal.GetModuleListDict()));
 }