public IActionResult Get([FromQuery] UsersGetMany filters)
        {
            Func <ApplicationUser, bool> p1 = u => true;

            if (!string.IsNullOrWhiteSpace(filters.Role))
            {
                p1 = u => u.IdentityUserRoles.Any(ur => ur.IdentityRole.Name.Trim().ToLower() == filters.Role.Trim().ToLower());
            }

            Func <ApplicationUser, bool> p2 = u => true;

            if (!string.IsNullOrWhiteSpace(filters.HiringType))
            {
                p2 = u => u.HiringType?.Trim().ToLower() == filters.HiringType.Trim().ToLower();
            }

            Func <ApplicationUser, bool> p3 = u => true;

            if (!string.IsNullOrWhiteSpace(filters.Company))
            {
                p3 = u => u.Company?.Trim().ToLower() == filters.Company.Trim().ToLower();
            }

            Func <ApplicationUser, bool> p4 = u => true;

            if (!string.IsNullOrWhiteSpace(filters.Department))
            {
                p4 = u => u.Department?.Trim().ToLower() == filters.Department.Trim().ToLower();
            }

            var allUsers = userManager.Users
                           .Include(u => u.IdentityUserRoles)
                           .ThenInclude(ur => ur.IdentityRole)
                           .Include(u => u.IdentityClaims)
                           .Where(p1)
                           .Where(p2)
                           .Where(p3)
                           .Where(p4)
                           .OrderBy(u => u.UserName)
                           .ToList();

            Parallel.ForEach(allUsers, user =>
            {
                user.IdentityUserRoles = user.IdentityUserRoles.Where(ur => ur.ClientId == userPrincipalBuilder.GetCurrentClientId()).ToList();
                user.IdentityClaims.Add(new ApplicationUserClaim()
                {
                    ClaimType  = FurizaClaimNames.ClientId,
                    ClaimValue = userPrincipalBuilder.GetCurrentClientId().ToString()
                });
            });

            var resultItems = mapper.Map <IEnumerable <ApplicationUser>, IEnumerable <UsersGetResult> >(allUsers);
            var result      = new UsersGetManyResult()
            {
                Users = resultItems
            };

            return(Ok(result));
        }
        public async override Task <bool> IsInRoleAsync(ApplicationUser user, string normalizedRoleName, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            ValidateParameters(user, normalizedRoleName);

            var roleEntity = await FindRoleAsync(normalizedRoleName, cancellationToken);

            if (roleEntity != null)
            {
                var roleAssignment = await FindUserRoleAsync(user.Id, roleEntity.Id, userPrincipalBuilder.GetCurrentClientId(), cancellationToken);

                return(roleAssignment != null);
            }

            return(false);
        }
Пример #3
0
        public async Task <bool> IsInScopedRoleAsync(string userName, string roleName, string scopeName, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            ValidateAndNormalizeParameters(userName, roleName, scopeName, out var normalizedUserName, out var normalizedRoleName, out var normalizedScopeName);

            var scopedRoleAssignment = await FindUserScopedRoleAsync(normalizedUserName, normalizedRoleName, normalizedScopeName, userPrincipalBuilder.GetCurrentClientId(), cancellationToken);

            return(scopedRoleAssignment != null);
        }