|
|
|
@ -208,32 +208,31 @@ public class EfCoreOrganizationUnitRepository |
|
|
|
int maxResultCount = int.MaxValue, |
|
|
|
int skipCount = 0, |
|
|
|
string filter = null, |
|
|
|
bool includeChildren = false, |
|
|
|
bool includeDetails = false, |
|
|
|
CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var query = await CreateGetMembersFilteredQueryAsync(organizationUnit, filter); |
|
|
|
var query = await CreateGetMembersFilteredQueryAsync(organizationUnit, filter, includeChildren); |
|
|
|
|
|
|
|
return await query.IncludeDetails(includeDetails).OrderBy(sorting.IsNullOrEmpty() ? nameof(IdentityUser.UserName) : sorting) |
|
|
|
.PageBy(skipCount, maxResultCount) |
|
|
|
.ToListAsync(GetCancellationToken(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) |
|
|
|
{ |
|
|
|
var dbContext = await GetDbContextAsync(); |
|
|
|
|
|
|
|
return await (from userOu in dbContext.Set<IdentityUserOrganizationUnit>() |
|
|
|
join user in dbContext.Users on userOu.UserId equals user.Id |
|
|
|
where userOu.OrganizationUnitId == id |
|
|
|
select user.Id).ToListAsync(cancellationToken); |
|
|
|
var organizationUnit = await GetAsync(id, cancellationToken: cancellationToken); |
|
|
|
var query = await CreateGetMembersFilteredQueryAsync(organizationUnit, null, includeChildren); |
|
|
|
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) |
|
|
|
{ |
|
|
|
var query = await CreateGetMembersFilteredQueryAsync(organizationUnit, filter); |
|
|
|
var query = await CreateGetMembersFilteredQueryAsync(organizationUnit, filter, includeChildren); |
|
|
|
|
|
|
|
return await query.CountAsync(GetCancellationToken(cancellationToken)); |
|
|
|
} |
|
|
|
@ -324,14 +323,33 @@ public class EfCoreOrganizationUnitRepository |
|
|
|
dbContext.Set<IdentityUserOrganizationUnit>().RemoveRange(ouMembersQuery); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual async Task<IQueryable<IdentityUser>> CreateGetMembersFilteredQueryAsync(OrganizationUnit organizationUnit, string filter = null) |
|
|
|
protected virtual async Task<IQueryable<IdentityUser>> CreateGetMembersFilteredQueryAsync( |
|
|
|
OrganizationUnit organizationUnit, |
|
|
|
string filter = null, |
|
|
|
bool includeChildren = false) |
|
|
|
{ |
|
|
|
var dbContext = await GetDbContextAsync(); |
|
|
|
|
|
|
|
var query = from userOu in dbContext.Set<IdentityUserOrganizationUnit>() |
|
|
|
join user in dbContext.Users on userOu.UserId equals user.Id |
|
|
|
where userOu.OrganizationUnitId == organizationUnit.Id |
|
|
|
select user; |
|
|
|
IQueryable<IdentityUser> query; |
|
|
|
if (includeChildren) |
|
|
|
{ |
|
|
|
var childrenIds = await (await GetDbSetAsync()) |
|
|
|
.Where(ou => ou.Code.StartsWith(organizationUnit.Code)) |
|
|
|
.Select(x => x.Id) |
|
|
|
.ToListAsync(); |
|
|
|
|
|
|
|
query = from userOu in dbContext.Set<IdentityUserOrganizationUnit>() |
|
|
|
join user in dbContext.Users on userOu.UserId equals user.Id |
|
|
|
where childrenIds.Contains(userOu.OrganizationUnitId) |
|
|
|
select user; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
query = from userOu in dbContext.Set<IdentityUserOrganizationUnit>() |
|
|
|
join user in dbContext.Users on userOu.UserId equals user.Id |
|
|
|
where userOu.OrganizationUnitId == organizationUnit.Id |
|
|
|
select user; |
|
|
|
} |
|
|
|
|
|
|
|
if (!filter.IsNullOrWhiteSpace()) |
|
|
|
{ |
|
|
|
|