Beispiel #1
0
        /// <summary>
        /// 查询该用户拥有哪些角色
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <ResponseMessage <List <RoleListResponse> > > SelectUserRoleAsync(string userid, CancellationToken cancellationToken = default(CancellationToken))
        {
            var response = new ResponseMessage <List <RoleListResponse> >()
            {
                Extension = new List <RoleListResponse> {
                }
            };

            if (await _userStore.GetAsync(userid) == null)
            {
                throw new ZCustomizeException(ResponseCodeEnum.NotAllow, "没有找到该用户,请重试");
            }
            var roleid = await _userRoleStore.IQueryableListAsync().Where(t => t.UserId == userid).Select(y => y.RoleId).ToListAsync(cancellationToken);

            _logger.LogInformation($"roleid:{JsonHelper.ToJson(roleid)}");
            var result = await _roleStore.IQueryableListAsync().Select(role => new RoleListResponse
            {
                Id          = role.Id,
                Name        = role.Name,
                IsAuthorize = roleid.Contains(role.Id) ? true : false
            }).ToListAsync();

            response.Extension = result;
            return(response);
        }
Beispiel #2
0
        /// <summary>
        /// 角色详情(查询所有拥有的权限)
        /// </summary>
        /// <param name="roleid"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <ResponseMessage <dynamic> > RoleDetailsAsync(string roleid, CancellationToken cancellationToken = default(CancellationToken))

        {
            var response = new ResponseMessage <dynamic>();
            var details  = from per in _permissionStore.IQueryableListAsync()
                           join role_permission in _rolePermissionStore.IQueryableListAsync()
                           on per.Id equals role_permission.PermissionId into s
                           from s1 in s.DefaultIfEmpty()
                           join role in _roleStore.IQueryableListAsync()
                           on s1.RoleId equals role.Id into t
                           from t1 in t.DefaultIfEmpty()
                           where t1.Id == roleid
                           select new
            {
                roleid         = t1.Id,
                rolename       = t1.Name,
                permissionid   = per.Id,
                permissionname = per.Name
            };

            response.Extension = await details.FirstOrDefaultAsync(cancellationToken);

            return(response);
        }