Ejemplo n.º 1
0
        public ActionResult RolePermission(Guid id)
        {
            RolePermissionViewModel model = new RolePermissionViewModel();

            model.CategoryList = _sysCategoryService.getAll();
            var roleList = _sysRoleService.getAllRoles();

            if (roleList != null && roleList.Any())
            {
                model.Role        = roleList.FirstOrDefault(o => o.Id == id);
                model.RoleList    = roleList;
                model.Permissions = _sysPermissionService.getByRoleId(id);
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 私有方法,获取当前用户的方法数据
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        private List <Entities.SysCategory> GetMyCategories(Entities.SysUser user)
        {
            var list = _sysCategoryService.getAll();

            if (user == null)
            {
                return(null);
            }
            if (user.IsAdmin)
            {
                return(list);
            }

            //获取权限数据
            var userRoles = _sysUserRoleService.getAll();

            if (userRoles == null || !userRoles.Any())
            {
                return(null);
            }
            var roleIds        = userRoles.Where(o => o.UserId == user.Id).Select(x => x.RoleId).Distinct().ToList();
            var permissionList = _sysPermissionServices.getAll();

            if (permissionList == null || !permissionList.Any())
            {
                return(null);
            }

            var categoryIds = permissionList.Where(o => roleIds.Contains(o.RoleId)).Select(x => x.CategoryId).Distinct().ToList();

            if (!categoryIds.Any())
            {
                return(null);
            }
            list = list.Where(o => categoryIds.Contains(o.Id)).ToList();
            return(list);
        }