Browse Source

refactored identity role repository for filtering

pull/4044/head
Akın Sabri Çam 6 years ago
parent
commit
5359b0c5fb
  1. 1
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs
  2. 12
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs
  3. 14
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs

1
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs

@ -18,6 +18,7 @@ namespace Volo.Abp.Identity
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
string filter = null,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );

12
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs

@ -19,7 +19,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
} }
public virtual async Task<IdentityRole> FindByNormalizedNameAsync( public virtual async Task<IdentityRole> FindByNormalizedNameAsync(
string normalizedRoleName, string normalizedRoleName,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -29,14 +29,18 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
} }
public virtual async Task<List<IdentityRole>> GetListAsync( public virtual async Task<List<IdentityRole>> GetListAsync(
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
string filter = null,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await DbSet return await DbSet
.IncludeDetails(includeDetails) .IncludeDetails(includeDetails)
.WhereIf(filter != null,
x => x.Name.Contains(filter) ||
x.NormalizedName.Contains(filter))
.OrderBy(sorting ?? nameof(IdentityRole.Name)) .OrderBy(sorting ?? nameof(IdentityRole.Name))
.PageBy(skipCount, maxResultCount) .PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));

14
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs

@ -14,13 +14,13 @@ namespace Volo.Abp.Identity.MongoDB
{ {
public class MongoIdentityRoleRepository : MongoDbRepository<IAbpIdentityMongoDbContext, IdentityRole, Guid>, IIdentityRoleRepository public class MongoIdentityRoleRepository : MongoDbRepository<IAbpIdentityMongoDbContext, IdentityRole, Guid>, IIdentityRoleRepository
{ {
public MongoIdentityRoleRepository(IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider) public MongoIdentityRoleRepository(IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider)
: base(dbContextProvider) : base(dbContextProvider)
{ {
} }
public async Task<IdentityRole> FindByNormalizedNameAsync( public async Task<IdentityRole> FindByNormalizedNameAsync(
string normalizedRoleName, string normalizedRoleName,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -28,13 +28,17 @@ namespace Volo.Abp.Identity.MongoDB
} }
public async Task<List<IdentityRole>> GetListAsync( public async Task<List<IdentityRole>> GetListAsync(
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
string filter = null,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.WhereIf(filter != null,
x => x.Name.Contains(filter) ||
x.NormalizedName.Contains(filter))
.OrderBy(sorting ?? nameof(IdentityRole.Name)) .OrderBy(sorting ?? nameof(IdentityRole.Name))
.As<IMongoQueryable<IdentityRole>>() .As<IMongoQueryable<IdentityRole>>()
.PageBy<IdentityRole, IMongoQueryable<IdentityRole>>(skipCount, maxResultCount) .PageBy<IdentityRole, IMongoQueryable<IdentityRole>>(skipCount, maxResultCount)

Loading…
Cancel
Save