|
|
|
@ -28,6 +28,30 @@ public class EfCoreIdentityRoleRepository : EfCoreRepository<IIdentityDbContext, |
|
|
|
.FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, GetCancellationToken(cancellationToken)); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<List<IdentityRoleWithUserCount>> GetListWithUserCountAsync( |
|
|
|
string sorting = null, |
|
|
|
int maxResultCount = int.MaxValue, |
|
|
|
int skipCount = 0, |
|
|
|
string filter = null, |
|
|
|
bool includeDetails = false, |
|
|
|
CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var roles = await GetListInternalAsync(sorting, maxResultCount, skipCount, filter, includeDetails, cancellationToken: cancellationToken); |
|
|
|
|
|
|
|
var roleIds = roles.Select(x => x.Id).ToList(); |
|
|
|
var userCount = await (await GetDbContextAsync()).Set<IdentityUserRole>() |
|
|
|
.Where(userRole => roleIds.Contains(userRole.RoleId)) |
|
|
|
.GroupBy(userRole => userRole.RoleId) |
|
|
|
.Select(x => new |
|
|
|
{ |
|
|
|
RoleId = x.Key, |
|
|
|
Count = x.Count() |
|
|
|
}) |
|
|
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
|
|
|
|
|
|
|
return roles.Select(role => new IdentityRoleWithUserCount(role, userCount.FirstOrDefault(x => x.RoleId == role.Id)?.Count ?? 0)).ToList(); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<List<IdentityRole>> GetListAsync( |
|
|
|
string sorting = null, |
|
|
|
int maxResultCount = int.MaxValue, |
|
|
|
@ -36,14 +60,7 @@ public class EfCoreIdentityRoleRepository : EfCoreRepository<IIdentityDbContext, |
|
|
|
bool includeDetails = true, |
|
|
|
CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
return await (await GetDbSetAsync()) |
|
|
|
.IncludeDetails(includeDetails) |
|
|
|
.WhereIf(!filter.IsNullOrWhiteSpace(), |
|
|
|
x => x.Name.Contains(filter) || |
|
|
|
x.NormalizedName.Contains(filter)) |
|
|
|
.OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityRole.Name) : sorting) |
|
|
|
.PageBy(skipCount, maxResultCount) |
|
|
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
|
|
|
return await GetListInternalAsync(sorting , maxResultCount, skipCount, filter, includeDetails, cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<List<IdentityRole>> GetListAsync( |
|
|
|
@ -75,6 +92,24 @@ public class EfCoreIdentityRoleRepository : EfCoreRepository<IIdentityDbContext, |
|
|
|
.LongCountAsync(GetCancellationToken(cancellationToken)); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual async Task<List<IdentityRole>> GetListInternalAsync( |
|
|
|
string sorting = null, |
|
|
|
int maxResultCount = int.MaxValue, |
|
|
|
int skipCount = 0, |
|
|
|
string filter = null, |
|
|
|
bool includeDetails = true, |
|
|
|
CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
return await (await GetDbSetAsync()) |
|
|
|
.IncludeDetails(includeDetails) |
|
|
|
.WhereIf(!filter.IsNullOrWhiteSpace(), |
|
|
|
x => x.Name.Contains(filter) || |
|
|
|
x.NormalizedName.Contains(filter)) |
|
|
|
.OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityRole.Name) : sorting) |
|
|
|
.PageBy(skipCount, maxResultCount) |
|
|
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
|
|
|
} |
|
|
|
|
|
|
|
[Obsolete("Use WithDetailsAsync")] |
|
|
|
public override IQueryable<IdentityRole> WithDetails() |
|
|
|
{ |
|
|
|
|