|
|
|
@ -189,11 +189,12 @@ public class MongoOrganizationUnitRepository |
|
|
|
int maxResultCount = int.MaxValue, |
|
|
|
int skipCount = 0, |
|
|
|
string filter = null, |
|
|
|
bool includeChildren = false, |
|
|
|
bool includeDetails = false, |
|
|
|
CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
cancellationToken = GetCancellationToken(cancellationToken); |
|
|
|
var query = await CreateGetMembersFilteredQueryAsync(organizationUnit, filter, cancellationToken); |
|
|
|
var query = await CreateGetMembersFilteredQueryAsync(organizationUnit, filter, includeChildren, cancellationToken); |
|
|
|
return await query |
|
|
|
.OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityUser.UserName) : sorting) |
|
|
|
.As<IMongoQueryable<IdentityUser>>() |
|
|
|
@ -201,21 +202,22 @@ public class MongoOrganizationUnitRepository |
|
|
|
.ToListAsync(cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<List<Guid>> GetMemberIdsAsync(Guid id, CancellationToken cancellationToken = default) |
|
|
|
public virtual async Task<List<Guid>> GetMemberIdsAsync(Guid id, bool includeChildren = false, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
cancellationToken = GetCancellationToken(cancellationToken); |
|
|
|
return await (await GetMongoQueryableAsync<IdentityUser>(cancellationToken)) |
|
|
|
.Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == id)).Select(x => x.Id) |
|
|
|
.ToListAsync(cancellationToken); |
|
|
|
var organizationUnit = await GetAsync(id, cancellationToken: cancellationToken); |
|
|
|
var query = await CreateGetMembersFilteredQueryAsync(organizationUnit, null, includeChildren, cancellationToken); |
|
|
|
return await query.Select(x => x.Id).ToListAsync(cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<int> GetMembersCountAsync( |
|
|
|
OrganizationUnit organizationUnit, |
|
|
|
string filter = null, |
|
|
|
bool includeChildren = false, |
|
|
|
CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
cancellationToken = GetCancellationToken(cancellationToken); |
|
|
|
var query = await CreateGetMembersFilteredQueryAsync(organizationUnit, filter, cancellationToken); |
|
|
|
var query = await CreateGetMembersFilteredQueryAsync(organizationUnit, filter, includeChildren, cancellationToken); |
|
|
|
return await query.CountAsync(cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
@ -286,8 +288,27 @@ public class MongoOrganizationUnitRepository |
|
|
|
protected virtual async Task<IMongoQueryable<IdentityUser>> CreateGetMembersFilteredQueryAsync( |
|
|
|
OrganizationUnit organizationUnit, |
|
|
|
string filter = null, |
|
|
|
bool includeChildren = false, |
|
|
|
CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
if (includeChildren) |
|
|
|
{ |
|
|
|
var childrenIds = await (await GetMongoQueryableAsync(cancellationToken)) |
|
|
|
.Where(ou => ou.Code.StartsWith(organizationUnit.Code)) |
|
|
|
.Select(ou => ou.Id) |
|
|
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
|
|
|
|
|
|
|
return (await GetMongoQueryableAsync<IdentityUser>(cancellationToken)) |
|
|
|
.Where(u => u.OrganizationUnits.Any(uou => childrenIds.Contains(uou.OrganizationUnitId))) |
|
|
|
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>( |
|
|
|
!filter.IsNullOrWhiteSpace(), |
|
|
|
u => |
|
|
|
u.UserName.Contains(filter) || |
|
|
|
u.Email.Contains(filter) || |
|
|
|
(u.PhoneNumber != null && u.PhoneNumber.Contains(filter)) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
return (await GetMongoQueryableAsync<IdentityUser>(cancellationToken)) |
|
|
|
.Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id)) |
|
|
|
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>( |
|
|
|
|