Browse Source

Update MongoIdentityUserRepository.cs

pull/21989/head
Mansur Besleney 2 years ago
parent
commit
2f67c20f7d
  1. 102
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs

102
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs

@ -25,7 +25,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync( .FirstOrDefaultAsync(
u => u.NormalizedUserName == normalizedUserName, u => u.NormalizedUserName == normalizedUserName,
@ -43,13 +43,13 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
.Select(r => r.OrganizationUnitId) .Select(r => r.OrganizationUnitId)
.ToArray(); .ToArray();
var organizationUnits = await (await GetMongoQueryableAsync<OrganizationUnit>(cancellationToken)) var organizationUnits = await (await GetQueryableAsync<OrganizationUnit>(cancellationToken))
.Where(ou => organizationUnitIds.Contains(ou.Id)) .Where(ou => organizationUnitIds.Contains(ou.Id))
.ToListAsync(cancellationToken: cancellationToken); .ToListAsync(cancellationToken: cancellationToken);
var orgUnitRoleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray(); var orgUnitRoleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray();
var roleIds = user.Roles.Select(r => r.RoleId).ToArray(); var roleIds = user.Roles.Select(r => r.RoleId).ToArray();
var allRoleIds = orgUnitRoleIds.Union(roleIds); var allRoleIds = orgUnitRoleIds.Union(roleIds);
return await (await GetMongoQueryableAsync<IdentityRole>(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).Select(r => r.Name).ToListAsync(cancellationToken); return await (await GetQueryableAsync<IdentityRole>(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).Select(r => r.Name).ToListAsync(cancellationToken);
} }
public virtual async Task<List<string>> GetRoleNamesInOrganizationUnitAsync( public virtual async Task<List<string>> GetRoleNamesInOrganizationUnitAsync(
@ -63,13 +63,13 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
.Select(r => r.OrganizationUnitId) .Select(r => r.OrganizationUnitId)
.ToArray(); .ToArray();
var organizationUnits = await (await GetMongoQueryableAsync<OrganizationUnit>(cancellationToken)) var organizationUnits = await (await GetQueryableAsync<OrganizationUnit>(cancellationToken))
.Where(ou => organizationUnitIds.Contains(ou.Id)) .Where(ou => organizationUnitIds.Contains(ou.Id))
.ToListAsync(cancellationToken: cancellationToken); .ToListAsync(cancellationToken: cancellationToken);
var roleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray(); var roleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray();
var queryable = await GetMongoQueryableAsync<IdentityRole>(cancellationToken); var queryable = await GetQueryableAsync<IdentityRole>(cancellationToken);
return await queryable return await queryable
.Where(r => roleIds.Contains(r.Id)) .Where(r => roleIds.Contains(r.Id))
@ -83,7 +83,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(u => u.Logins.Any(login => login.LoginProvider == loginProvider && login.ProviderKey == providerKey)) .Where(u => u.Logins.Any(login => login.LoginProvider == loginProvider && login.ProviderKey == providerKey))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
@ -94,7 +94,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.OrderBy(x => x.Id).FirstOrDefaultAsync(u => u.NormalizedEmail == normalizedEmail, GetCancellationToken(cancellationToken)); .OrderBy(x => x.Id).FirstOrDefaultAsync(u => u.NormalizedEmail == normalizedEmail, GetCancellationToken(cancellationToken));
} }
@ -103,14 +103,14 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(u => u.Claims.Any(c => c.ClaimType == claim.Type && c.ClaimValue == claim.Value)) .Where(u => u.Claims.Any(c => c.ClaimType == claim.Type && c.ClaimValue == claim.Value))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task RemoveClaimFromAllUsersAsync(string claimType, bool autoSave, CancellationToken cancellationToken = default) public virtual async Task RemoveClaimFromAllUsersAsync(string claimType, bool autoSave, CancellationToken cancellationToken = default)
{ {
var users = await (await GetMongoQueryableAsync(cancellationToken)) var users = await (await GetQueryableAsync(cancellationToken))
.Where(u => u.Claims.Any(c => c.ClaimType == claimType)) .Where(u => u.Claims.Any(c => c.ClaimType == claimType))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
@ -129,7 +129,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
var queryable = await GetMongoQueryableAsync<IdentityRole>(cancellationToken); var queryable = await GetQueryableAsync<IdentityRole>(cancellationToken);
var role = await queryable var role = await queryable
.Where(x => x.NormalizedName == normalizedRoleName) .Where(x => x.NormalizedName == normalizedRoleName)
@ -141,7 +141,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
return new List<IdentityUser>(); return new List<IdentityUser>();
} }
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(u => u.Roles.Any(r => r.RoleId == role.Id)) .Where(u => u.Roles.Any(r => r.RoleId == role.Id))
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
} }
@ -150,7 +150,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(u => u.Roles.Any(r => r.RoleId == roleId)) .Where(u => u.Roles.Any(r => r.RoleId == roleId))
.Select(x => x.Id) .Select(x => x.Id)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
@ -203,8 +203,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
return await query return await query
.OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityUser.CreationTime) + " desc" : sorting) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityUser.CreationTime) + " desc" : sorting)
.As<IMongoQueryable<IdentityUser>>() .PageBy(skipCount, maxResultCount)
.PageBy<IdentityUser, IMongoQueryable<IdentityUser>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -219,13 +218,13 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
.Select(r => r.OrganizationUnitId) .Select(r => r.OrganizationUnitId)
.ToArray(); .ToArray();
var organizationUnits = await (await GetMongoQueryableAsync<OrganizationUnit>(cancellationToken)) var organizationUnits = await (await GetQueryableAsync<OrganizationUnit>(cancellationToken))
.Where(ou => organizationUnitIds.Contains(ou.Id)) .Where(ou => organizationUnitIds.Contains(ou.Id))
.ToListAsync(cancellationToken: cancellationToken); .ToListAsync(cancellationToken: cancellationToken);
var orgUnitRoleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray(); var orgUnitRoleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray();
var roleIds = user.Roles.Select(r => r.RoleId).ToArray(); var roleIds = user.Roles.Select(r => r.RoleId).ToArray();
var allRoleIds = orgUnitRoleIds.Union(roleIds); var allRoleIds = orgUnitRoleIds.Union(roleIds);
return await (await GetMongoQueryableAsync<IdentityRole>(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).ToListAsync(cancellationToken); return await (await GetQueryableAsync<IdentityRole>(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).ToListAsync(cancellationToken);
} }
public virtual async Task<List<OrganizationUnit>> GetOrganizationUnitsAsync( public virtual async Task<List<OrganizationUnit>> GetOrganizationUnitsAsync(
@ -237,7 +236,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
var user = await GetAsync(id, cancellationToken: cancellationToken); var user = await GetAsync(id, cancellationToken: cancellationToken);
var organizationUnitIds = user.OrganizationUnits.Select(r => r.OrganizationUnitId); var organizationUnitIds = user.OrganizationUnits.Select(r => r.OrganizationUnitId);
return await (await GetMongoQueryableAsync<OrganizationUnit>(cancellationToken)) return await (await GetQueryableAsync<OrganizationUnit>(cancellationToken))
.Where(ou => organizationUnitIds.Contains(ou.Id)) .Where(ou => organizationUnitIds.Contains(ou.Id))
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
} }
@ -290,7 +289,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
Guid organizationUnitId, Guid organizationUnitId,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var result = await (await GetMongoQueryableAsync(cancellationToken)) var result = await (await GetQueryableAsync(cancellationToken))
.Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnitId)) .Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnitId))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
return result; return result;
@ -300,7 +299,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
List<Guid> organizationUnitIds, List<Guid> organizationUnitIds,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var result = await (await GetMongoQueryableAsync(cancellationToken)) var result = await (await GetQueryableAsync(cancellationToken))
.Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId))) .Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId)))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
return result; return result;
@ -312,12 +311,12 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
{ {
cancellationToken = GetCancellationToken(cancellationToken); cancellationToken = GetCancellationToken(cancellationToken);
var organizationUnitIds = await (await GetMongoQueryableAsync<OrganizationUnit>(cancellationToken)) var organizationUnitIds = await (await GetQueryableAsync<OrganizationUnit>(cancellationToken))
.Where(ou => ou.Code.StartsWith(code)) .Where(ou => ou.Code.StartsWith(code))
.Select(ou => ou.Id) .Select(ou => ou.Id)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId))) .Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId)))
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
} }
@ -328,7 +327,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.FirstOrDefaultAsync( .FirstOrDefaultAsync(
u => u.TenantId == tenantId && u.UserName == userName, u => u.TenantId == tenantId && u.UserName == userName,
GetCancellationToken(cancellationToken) GetCancellationToken(cancellationToken)
@ -337,14 +336,14 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
public virtual async Task<List<IdentityUser>> GetListByIdsAsync(IEnumerable<Guid> ids, bool includeDetails = false, CancellationToken cancellationToken = default) public virtual async Task<List<IdentityUser>> GetListByIdsAsync(IEnumerable<Guid> ids, bool includeDetails = false, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetQueryableAsync(cancellationToken))
.Where(x => ids.Contains(x.Id)) .Where(x => ids.Contains(x.Id))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task UpdateRoleAsync(Guid sourceRoleId, Guid? targetRoleId, CancellationToken cancellationToken = default) public virtual async Task UpdateRoleAsync(Guid sourceRoleId, Guid? targetRoleId, CancellationToken cancellationToken = default)
{ {
var users = await (await GetMongoQueryableAsync(cancellationToken)) var users = await (await GetQueryableAsync(cancellationToken))
.Where(x => x.Roles.Any(r => r.RoleId == sourceRoleId)) .Where(x => x.Roles.Any(r => r.RoleId == sourceRoleId))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
@ -362,7 +361,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
public virtual async Task UpdateOrganizationAsync(Guid sourceOrganizationId, Guid? targetOrganizationId, CancellationToken cancellationToken = default) public virtual async Task UpdateOrganizationAsync(Guid sourceOrganizationId, Guid? targetOrganizationId, CancellationToken cancellationToken = default)
{ {
var users = await (await GetMongoQueryableAsync(cancellationToken)) var users = await (await GetQueryableAsync(cancellationToken))
.Where(x => x.OrganizationUnits.Any(r => r.OrganizationUnitId == sourceOrganizationId)) .Where(x => x.OrganizationUnits.Any(r => r.OrganizationUnitId == sourceOrganizationId))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
@ -394,16 +393,15 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
var organizationUnitIds = userAndOrganizationUnitIds.SelectMany(x => x.Value); var organizationUnitIds = userAndOrganizationUnitIds.SelectMany(x => x.Value);
var roleIds = userAndRoleIds.SelectMany(x => x.Value); var roleIds = userAndRoleIds.SelectMany(x => x.Value);
var organizationUnitAndRoleIds = await (await GetMongoQueryableAsync<OrganizationUnit>(cancellationToken)).Where(ou => organizationUnitIds.Contains(ou.Id)) var organizationUnitAndRoleIds = await (await GetQueryableAsync<OrganizationUnit>(cancellationToken)).Where(ou => organizationUnitIds.Contains(ou.Id))
.Select(userOrganizationUnit => new .Select(userOrganizationUnit => new {
{
userOrganizationUnit.Id, userOrganizationUnit.Id,
userOrganizationUnit.Roles userOrganizationUnit.Roles
}).ToListAsync(cancellationToken: cancellationToken); }).ToListAsync(cancellationToken: cancellationToken);
var allOrganizationUnitRoleIds = organizationUnitAndRoleIds.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToList(); var allOrganizationUnitRoleIds = organizationUnitAndRoleIds.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToList();
var allRoleIds = roleIds.Union(allOrganizationUnitRoleIds); var allRoleIds = roleIds.Union(allOrganizationUnitRoleIds);
var roles = await (await GetMongoQueryableAsync<IdentityRole>(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).Select(r => new{ r.Id, r.Name }).ToListAsync(cancellationToken); var roles = await (await GetQueryableAsync<IdentityRole>(cancellationToken)).Where(r => allRoleIds.Contains(r.Id)).Select(r => new { r.Id, r.Name }).ToListAsync(cancellationToken);
var userRoles = userAndRoleIds.ToDictionary(x => x.Key, x => roles.Where(r => x.Value.Contains(r.Id)).Select(r => r.Name).ToArray()); var userRoles = userAndRoleIds.ToDictionary(x => x.Key, x => roles.Where(r => x.Value.Contains(r.Id)).Select(r => r.Name).ToArray());
var result = userRoles.Select(x => new IdentityUserIdWithRoleNames { Id = x.Key, RoleNames = x.Value }).ToList(); var result = userRoles.Select(x => new IdentityUserIdWithRoleNames { Id = x.Key, RoleNames = x.Value }).ToList();
@ -417,16 +415,16 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
{ {
user.RoleNames = user.RoleNames.Union(roleNames).ToArray(); user.RoleNames = user.RoleNames.Union(roleNames).ToArray();
} }
else if(roleNames.Any()) else if (roleNames.Any())
{ {
result.Add(new IdentityUserIdWithRoleNames { Id = userAndOrganizationUnitId.Key, RoleNames = roleNames}); result.Add(new IdentityUserIdWithRoleNames { Id = userAndOrganizationUnitId.Key, RoleNames = roleNames });
} }
} }
return result; return result;
} }
protected virtual async Task<IMongoQueryable<IdentityUser>> GetFilteredQueryableAsync( protected virtual async Task<IQueryable<IdentityUser>> GetFilteredQueryableAsync(
string filter = null, string filter = null,
Guid? roleId = null, Guid? roleId = null,
Guid? organizationUnitId = null, Guid? organizationUnitId = null,
@ -447,11 +445,11 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var upperFilter = filter?.ToUpperInvariant(); var upperFilter = filter?.ToUpperInvariant();
var query = await GetMongoQueryableAsync(cancellationToken); var query = await GetQueryableAsync(cancellationToken);
if (roleId.HasValue) if (roleId.HasValue)
{ {
var organizationUnitIds = (await GetMongoQueryableAsync<OrganizationUnit>(cancellationToken)) var organizationUnitIds = (await GetQueryableAsync<OrganizationUnit>(cancellationToken))
.Where(ou => ou.Roles.Any(r => r.RoleId == roleId.Value)) .Where(ou => ou.Roles.Any(r => r.RoleId == roleId.Value))
.Select(userOrganizationUnit => userOrganizationUnit.Id) .Select(userOrganizationUnit => userOrganizationUnit.Id)
.ToArray(); .ToArray();
@ -460,7 +458,7 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
} }
return query return query
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>( .WhereIf(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
u => u =>
u.NormalizedUserName.Contains(upperFilter) || u.NormalizedUserName.Contains(upperFilter) ||
@ -469,21 +467,21 @@ public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDb
(u.Surname != null && u.Surname.Contains(filter)) || (u.Surname != null && u.Surname.Contains(filter)) ||
(u.PhoneNumber != null && u.PhoneNumber.Contains(filter)) (u.PhoneNumber != null && u.PhoneNumber.Contains(filter))
) )
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(organizationUnitId.HasValue, identityUser => identityUser.OrganizationUnits.Any(x => x.OrganizationUnitId == organizationUnitId.Value)) .WhereIf(organizationUnitId.HasValue, identityUser => identityUser.OrganizationUnits.Any(x => x.OrganizationUnitId == organizationUnitId.Value))
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(!string.IsNullOrWhiteSpace(userName), x => x.UserName == userName) .WhereIf(!string.IsNullOrWhiteSpace(userName), x => x.UserName == userName)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(!string.IsNullOrWhiteSpace(phoneNumber), x => x.PhoneNumber == phoneNumber) .WhereIf(!string.IsNullOrWhiteSpace(phoneNumber), x => x.PhoneNumber == phoneNumber)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(!string.IsNullOrWhiteSpace(emailAddress), x => x.Email == emailAddress) .WhereIf(!string.IsNullOrWhiteSpace(emailAddress), x => x.Email == emailAddress)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(!string.IsNullOrWhiteSpace(name), x => x.Name == name) .WhereIf(!string.IsNullOrWhiteSpace(name), x => x.Name == name)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(!string.IsNullOrWhiteSpace(surname), x => x.Surname == surname) .WhereIf(!string.IsNullOrWhiteSpace(surname), x => x.Surname == surname)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(isLockedOut.HasValue && isLockedOut.Value, x => x.LockoutEnabled && x.LockoutEnd != null && x.LockoutEnd > DateTimeOffset.UtcNow) .WhereIf(isLockedOut.HasValue && isLockedOut.Value, x => x.LockoutEnabled && x.LockoutEnd != null && x.LockoutEnd > DateTimeOffset.UtcNow)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(isLockedOut.HasValue && !isLockedOut.Value, x => !(x.LockoutEnabled && x.LockoutEnd != null && x.LockoutEnd > DateTimeOffset.UtcNow)) .WhereIf(isLockedOut.HasValue && !isLockedOut.Value, x => !(x.LockoutEnabled && x.LockoutEnd != null && x.LockoutEnd > DateTimeOffset.UtcNow))
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(notActive.HasValue, x => x.IsActive == !notActive.Value) .WhereIf(notActive.HasValue, x => x.IsActive == !notActive.Value)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(emailConfirmed.HasValue, x => x.EmailConfirmed == emailConfirmed.Value) .WhereIf(emailConfirmed.HasValue, x => x.EmailConfirmed == emailConfirmed.Value)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(isExternal.HasValue, x => x.IsExternal == isExternal.Value) .WhereIf(isExternal.HasValue, x => x.IsExternal == isExternal.Value)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(maxCreationTime != null, p => p.CreationTime <= maxCreationTime) .WhereIf(maxCreationTime != null, p => p.CreationTime <= maxCreationTime)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(minCreationTime != null, p => p.CreationTime >= minCreationTime) .WhereIf(minCreationTime != null, p => p.CreationTime >= minCreationTime)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(maxModifitionTime != null, p => p.LastModificationTime <= maxModifitionTime) .WhereIf(maxModifitionTime != null, p => p.LastModificationTime <= maxModifitionTime)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(minModifitionTime != null, p => p.LastModificationTime >= minModifitionTime) .WhereIf(minModifitionTime != null, p => p.LastModificationTime >= minModifitionTime)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(id.HasValue, x => x.Id == id); .WhereIf(id.HasValue, x => x.Id == id);
} }
} }
Loading…
Cancel
Save