Example #1
0
        /// <summary>
        /// 利用遞迴方式 取得該角色下所有選單功能 無限追朔下層
        /// </summary>
        /// <param name="muID"></param>
        private MenuLinkModel GetMenuFunctionAllValidForRoleID(string muID, int roleID)
        {
            MenuModule    menuModule = new MenuModule();
            var           menu       = menuModule.GetMenuDataByID(muID);
            MenuLinkModel model      = new MenuLinkModel()
            {
                MenuID             = menu.MenuID,
                ParentMenuID       = menu.ParentMenuID,
                MenuName           = menu.MenuName,
                Enabled            = (bool)menu.Enabled,
                MenuEnabled        = (bool)menu.MenuEnabled,
                MenuPathController = menu.MenuPathController,
                MenuPathAction     = menu.MenuPathAction,
                MenuPath           = menu.MenuPath,
                MenuSort           = menu.MenuSort,
                MenuIcon           = menu.MenuIcon
            };
            //取下層
            var findSub = this.DB.PTMenu.Join(this.DB.PTRoleMenuMap,
                                              t1 => t1.MUID,
                                              t2 => t2.MAP_MUID,
                                              (m, r) => new
            {
                RoleID       = r.MAP_ROLEID,
                ParentMenuID = m.MUPID,
                MenuID       = m.MUID
            })
                          .Where(s => s.RoleID == roleID && s.ParentMenuID == muID)
                          .ToList();

            foreach (var sub in findSub)
            {
                model.SubMenu.Add(GetMenuFunctionAllValidForRoleID(sub.MenuID, roleID));
            }

            return(model);
        }
Example #2
0
        /// <summary>
        //  取出所有角色之下的目錄並移除重複
        /// </summary>
        /// <param name="roleList"></param>
        /// <returns></returns>
        public List <MenuLinkModel> GetMenuListByRoleList(List <RoleModel> roleList)
        {
            List <string> muIDList = new List <string>();

            foreach (var r in roleList)
            {
                foreach (var m in r.MenuList)
                {
                    muIDList.Add(m.MenuID);
                    m.SubMenu.ForEach(f =>
                    {
                        muIDList.Add(f.MenuID);
                        muIDList.AddRange(AddSubMenu(f));
                    }
                                      );
                }
            }
            muIDList = muIDList.Distinct().ToList();

            List <MenuLinkModel> muModelList = new List <MenuLinkModel>();
            MenuLinkModel        model       = new MenuLinkModel();
            MenuModule           menuModule  = new MenuModule();

            foreach (var mu in muIDList)
            {
                var menu = menuModule.GetMenuDataByID(mu);
                model = new MenuLinkModel()
                {
                    MenuID             = menu.MenuID,
                    ParentMenuID       = menu.ParentMenuID,
                    MenuName           = menu.MenuName,
                    Enabled            = (bool)menu.Enabled,
                    MenuEnabled        = (bool)menu.MenuEnabled,
                    MenuPathController = menu.MenuPathController,
                    MenuPathAction     = menu.MenuPathAction,
                    MenuPath           = menu.MenuPath,
                    MenuSort           = menu.MenuSort,
                    MenuIcon           = menu.MenuIcon
                };

                if (mu.Length == 1)
                {
                    if (!muModelList.Contains(model))
                    {
                        muModelList.Add(model);
                    }
                }
                //找尋第一層
                var find = muModelList.Where(o => o.MenuID == model.ParentMenuID).FirstOrDefault();
                if (find != null)
                {
                    find.SubMenu.Add(model);
                }
                else
                {
                    //找尋無限下層
                    foreach (var m in muModelList)
                    {
                        if (model.ParentMenuID == null)
                        {
                            break;
                        }
                        var findSubMenu = FindSubMenu(m, model);
                    }
                }
            }
            return(muModelList);
        }