예제 #1
0
        /// <summary>
        /// 获取当前声明的所有用户。
        /// </summary>
        /// <param name="claim">声明实例。</param>
        /// <param name="cancellationToken">取消标志。</param>
        /// <returns>
        /// 返回用户列表。
        /// </returns>
        public override async Task <IList <TUser> > GetUsersForClaimAsync(Claim claim, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (claim == null)
            {
                throw new ArgumentNullException(nameof(claim));
            }

            var users = await UserContext.AsQueryable().InnerJoin <TUserClaim>((u, c) => u.Id == c.UserId)
                        .Where <TUserClaim>(x => x.ClaimType == claim.Type && x.ClaimValue == claim.Value)
                        .AsEnumerableAsync(cancellationToken);

            return(users.ToList());
        }
예제 #2
0
        /// <summary>
        /// 检索当前角色的所有用户列表。
        /// </summary>
        /// <param name="normalizedRoleName">验证角色名称。</param>
        /// <param name="cancellationToken">取消标志。</param>
        /// <returns>
        /// 返回用户列表。
        /// </returns>
        public override async Task <IList <TUser> > GetUsersInRoleAsync(string normalizedRoleName, CancellationToken cancellationToken = default)
        {
            var role = await RoleManager.FindByNameAsync(normalizedRoleName);

            if (role == null)
            {
                return(null);
            }
            var users = await UserContext.AsQueryable()
                        .InnerJoin <TUserRole>((u, ur) => u.UserId == ur.UserId)
                        .Where <TUserRole>(x => x.RoleId == role.RoleId)
                        .AsEnumerableAsync(cancellationToken);

            return(users.ToList());
        }