public PermissionViewModule GetAllPermission()
        {
            var permissions = new PermissionViewModule();

            permissions.Modules   = this.DbContext.IMS_UP_MK_S.ToList();
            permissions.Functions = this.DbContext.IMS_UP_MKGN_S.ToList();
            return(permissions);
        }
        public PermissionViewModule GetPermissionListByUserID(string userid)
        {
            //            select m.* from IMS_UP_ModuT m
            //left join IMS_UP_RoMoT. p on p.ModuleID = m.ModuleID  and p.FunctionID = -1
            //left join IMS_UP_RoUrSet r on p.RoleId = r.RoleID
            //where r.UserID ='0001'

            var modList = from m in this.DbContext.IMS_UP_MK_S
                          join p in this.DbContext.IMS_UP_JSMK_S.Where(n => n.GNID == -1)
                          on m.MKID equals p.MKID into v_per
                          from v in v_per
                          join r in this.DbContext.IMS_UP_JSYH_S
                          on v.JSID equals r.JSID into v_ret
                          from r in v_ret
                          where r.YHID == userid
                          select m;

            // 同一个用户可能有多个角色, 角色的权限可能重复,所以distinct一下,去重
            modList = modList.Distinct();

            //select f.* from IMS_UP_MoFnT f
            //left join IMS_UP_RoMoT. p on p.ModuleID = f.ModuleID  and p.FunctionID = f.FunctionID
            //left join IMS_UP_RoUrSet r on p.RoleId = r.RoleID
            //where r.UserID ='0001'

            var funList = from f in this.DbContext.IMS_UP_MKGN_S
                          join p in this.DbContext.IMS_UP_JSMK_S
                          on new
            {
                mod = f.MKID,
                fun = (int?)f.GNID
            }
            equals new
            {
                mod = p.MKID,
                fun = p.GNID
            }
            into v_per
            from v in v_per
            join r in this.DbContext.IMS_UP_JSYH_S
            on v.JSID equals r.JSID into v_ret
            from r in v_ret
            where r.YHID == userid
            select f;

            // 同一个用户可能有多个角色, 角色的权限可能重复,所以distinct一下,去重
            funList = funList.Distinct();

            // 不分层的权限处理
            var permissions = new PermissionViewModule();

            permissions.Modules   = modList.ToList();
            permissions.Functions = funList.ToList();

            return(permissions);
        }
        public PartialViewResult _MenuPartial()
        {
            var menuList = new List <IMS_UP_MK>();

            var rootModuleList = dalModule.GetRootModule();

            if (rootModuleList == null)
            {
                return(PartialView(null));
            }

            var rootMenus = rootModuleList.OrderBy(n => n.PXID);

            PermissionViewModule permissionModule = null;

            if (CurrentUser.IsAdmin)
            {
                //dalPermission.GetAllEntites

                permissionModule = ActionPermission.GetAllPermission();
            }
            else
            {
                if (!User.Identity.IsAuthenticated)
                {
                    permissionModule = null;
                }
                else
                {
                    var user = CurrentUser.GetCurrentUser();
                    permissionModule = user.Permissions;
                }
            }


            if (permissionModule == null)
            {
                return(PartialView(menuList));
            }

            foreach (var m in rootMenus)
            {
                var perList = permissionModule.Modules.Where(n => n.FMKID == m.MKID).OrderBy(n => n.PXID);

                //var userPermissionList = user.Permissions.Modules.Where(n => n.ParentID == m.ModuleID);

                // 有子项菜单才需要显示
                if (perList.Count() > 0)
                {
                    menuList.Add(m);
                    menuList.AddRange(perList);
                    //foreach (var p in perList)
                    //    menuList.Add(p);
                }

                //var x = dalModule.GetChildModuleList(m.ModuleID);
                //menuList.AddRange(x);
            }

            foreach (var m in menuList)
            {
                // 根节点不需要url地址
                if (m.FMKID == -1)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(m.QY))
                {
                    m.URL = Url.Action(m.HDMC, m.KZMC);
                }
                else
                {
                    m.URL = Url.Action(m.HDMC, m.KZMC, new { area = m.QY });
                }
            }

            return(PartialView(menuList));
        }