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 Task OnGetAsync() { UsersGetManyResult = await usersClient.GetAsync(new UsersGetMany()); }