Example #1
0
        public ActionResult Index(int id = 0, int roleId = 0)
        {
            Utility.GetModelState(this);

            var modules       = _cache.Get(Constants.CACHE_KEY_MODULES, () => _module.GetList());
            var actionModules = _cache.Get(Constants.CACHE_KEY_ACTIONMODULE, () => _actionModule.GetList());
            var roles         = _cache.Get(Constants.CACHE_KEY_ROLES, () => _role.GetList());
            var actions       = _cache.Get(Constants.CACHE_KEY_ACTIONS, () => _action.GetList());
            var userRoles     = _userRole.GetList(Utility.CurrentLoginModel.UserId);

            IEnumerable <RoleEntry> roleList = null;

            if (roles != null && roles.Any())
            {
                var list = roles.Where(x => userRoles.Any(m => m.RoleId == x.RoleId && m.Status)).ToList();

                var maxGrade     = roles.Max(x => x.SeqNo);
                var currentGrade = list.Max(x => x.SeqNo);

                //当前等级 等于 系统中 最大权限等级 那么当前用户是超级管理员
                if (currentGrade == maxGrade)
                {
                    roleList = roles;
                }
                else
                {
                    roleList = roles.Where(x => x.SeqNo < currentGrade);
                }

                roleId = roleId == 0 ? roleList.FirstOrDefault(x => x.SeqNo == roleList.Min(m => m.SeqNo)).RoleId : roleId;
            }

            var roleRights = _roleRight.GetList(roleId);
            var filters    = modules.Where(x => x.DisplayAsMenu);
            var tree       = TreeUtils.GetTree(filters, id);

            ViewBag.Module     = tree;
            ViewBag.Actions    = actions;
            ViewBag.ModuleList = modules;
            ViewBag.CurrentId  = id;
            ViewBag.RoleId     = roleId;
            ViewBag.RoleRights = roleRights;

            ViewBag.Roles = new SelectList(roleList, "RoleId", "DisplayName", roleId);

            return(View(actionModules));
        }