Browse Source

added GetList method for sorting and filtering

pull/3732/head
Galip Tolga Erdem 6 years ago
parent
commit
58f1959cb3
  1. 12
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs
  2. 36
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs
  3. 29
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs
  4. 11
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs
  5. 51
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs

12
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs

@ -19,11 +19,17 @@ namespace Volo.Abp.Identity
Guid? parentId,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<List<OrganizationUnit>> GetListAsync(
IEnumerable<Guid> ids,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<List<OrganizationUnit>> GetListAsync(
IEnumerable<Guid> ids,
bool includeDetails = false,
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
bool includeDetails = true,
CancellationToken cancellationToken = default
);

36
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs

@ -6,7 +6,7 @@ using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Internal;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
@ -20,7 +20,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
}
public virtual async Task<IdentityUser> FindByNormalizedUserNameAsync(
string normalizedUserName,
string normalizedUserName,
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
@ -33,15 +33,15 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
}
public virtual async Task<List<string>> GetRoleNamesAsync(
Guid id,
Guid id,
CancellationToken cancellationToken = default)
{
var query = from userRole in DbContext.Set<IdentityUserRole>()
join role in DbContext.Roles on userRole.RoleId equals role.Id
where userRole.UserId == id
select role.Name;
var organizationUnitIds = DbContext.Set<IdentityUserOrganizationUnit>().Where(q => q.UserId == id).Select(q => q.OrganizationUnitId).ToArray();
var organizationRoleIds = DbContext.Set<OrganizationUnitRole>().Where(our => organizationUnitIds.Contains(our.OrganizationUnitId)).Select(r => r.RoleId).ToArray();
select role.Name;
var organizationUnitIds = DbContext.Set<IdentityUserOrganizationUnit>().Where(q => q.UserId == id).Select(q => q.OrganizationUnitId).ToArray();
var organizationRoleIds = DbContext.Set<OrganizationUnitRole>().Where(our => organizationUnitIds.Contains(our.OrganizationUnitId)).Select(r => r.RoleId).ToArray();
var orgUnitRoleNameQuery = DbContext.Roles.Where(r => organizationRoleIds.Contains(r.Id)).Select(n => n.Name);
var resultQuery = query.Union(orgUnitRoleNameQuery);
return await resultQuery.ToListAsync(GetCancellationToken(cancellationToken));
@ -61,8 +61,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
}
public virtual async Task<IdentityUser> FindByLoginAsync(
string loginProvider,
string providerKey,
string loginProvider,
string providerKey,
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
@ -94,7 +94,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
}
public virtual async Task<List<IdentityUser>> GetListByNormalizedRoleNameAsync(
string normalizedRoleName,
string normalizedRoleName,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
@ -114,10 +114,10 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
}
public virtual async Task<List<IdentityUser>> GetListAsync(
string sorting = null,
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
string filter = null,
int skipCount = 0,
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
@ -142,9 +142,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
var query = from userRole in DbContext.Set<IdentityUserRole>()
join role in DbContext.Roles.IncludeDetails(includeDetails) on userRole.RoleId equals role.Id
where userRole.UserId == id
select role;
//TODO: Needs improvement
select role;
//TODO: Needs improvement
var userOrganizationsQuery = from userOrg in DbContext.Set<IdentityUserOrganizationUnit>()
join ou in DbContext.OrganizationUnits.IncludeDetails(includeDetails) on userOrg.OrganizationUnitId equals ou.Id
where userOrg.UserId == id
@ -156,13 +156,13 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
var orgRoles = DbContext.Roles.Where(q => orgUserRoleQuery.Contains(q.Id));
var resultQuery = query.Union(orgRoles);
return await resultQuery.ToListAsync(GetCancellationToken(cancellationToken));
return await resultQuery.ToListAsync(GetCancellationToken(cancellationToken));
//return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<long> GetCountAsync(
string filter = null,
string filter = null,
CancellationToken cancellationToken = default)
{
return await this.WhereIf(

29
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs

@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq.Dynamic.Core;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -43,8 +44,21 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
}
public async Task<List<OrganizationUnit>> GetListAsync(
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
return await DbSet
.IncludeDetails(includeDetails)
.OrderBy(sorting ?? nameof(OrganizationUnit.DisplayName))
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<OrganizationUnit>> GetListAsync(
IEnumerable<Guid> ids,
bool includeDetails = false,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await DbSet
@ -54,8 +68,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
}
public async Task<OrganizationUnit> GetOrganizationUnitAsync(
string displayName,
bool includeDetails = false,
string displayName,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await DbSet
@ -64,9 +78,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
ou => ou.DisplayName == displayName,
GetCancellationToken(cancellationToken)
);
}
}
public async Task<List<IdentityRole>> GetOrganizationUnitRoles(
Guid organizationUnitId, bool includeDetails = false,
Guid organizationUnitId, bool includeDetails = false,
CancellationToken cancellationToken = default)
{
var query = from organizationRole in DbContext.Set<OrganizationUnitRole>()
@ -81,6 +95,11 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
{
return GetQueryable().IncludeDetails();
}
}
public class OrganizationUnitRoleWithIdentityRole
{
public IdentityRole IdentityRole { get; set; }
public OrganizationUnitRole OrganizationUnitRole { get; set; }
}
}

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

@ -7,20 +7,19 @@ using System.Linq.Dynamic.Core;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.Guids;
using Volo.Abp.MongoDB;
namespace Volo.Abp.Identity.MongoDB
{
public class MongoIdentityRoleRepository : MongoDbRepository<IAbpIdentityMongoDbContext, IdentityRole, Guid>, IIdentityRoleRepository
{
public MongoIdentityRoleRepository(IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider)
public MongoIdentityRoleRepository(IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public async Task<IdentityRole> FindByNormalizedNameAsync(
string normalizedRoleName,
string normalizedRoleName,
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
@ -28,9 +27,9 @@ namespace Volo.Abp.Identity.MongoDB
}
public async Task<List<IdentityRole>> GetListAsync(
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{

51
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs

@ -3,6 +3,7 @@ using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.MongoDB;
@ -19,7 +20,7 @@ namespace Volo.Abp.Identity.MongoDB
}
public async Task<List<OrganizationUnit>> GetChildrenAsync(
Guid? parentId,
Guid? parentId,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
@ -29,29 +30,43 @@ namespace Volo.Abp.Identity.MongoDB
}
public async Task<List<OrganizationUnit>> GetAllChildrenWithParentCodeAsync(
string code,
Guid? parentId,
string code,
Guid? parentId,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.Where(ou => ou.Code.StartsWith(code) && ou.Id != parentId.Value)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<OrganizationUnit>> GetListAsync(
IEnumerable<Guid> ids,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.Where(t => ids.Contains(t.Id))
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<OrganizationUnit>> GetListAsync(
IEnumerable<Guid> ids,
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.Where(t => ids.Contains(t.Id))
.OrderBy(sorting ?? nameof(OrganizationUnit.DisplayName))
.As<IMongoQueryable<OrganizationUnit>>()
.PageBy<OrganizationUnit, IMongoQueryable<OrganizationUnit>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<OrganizationUnit> GetOrganizationUnitAsync(
string displayName,
bool includeDetails = false,
string displayName,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
@ -59,16 +74,16 @@ namespace Volo.Abp.Identity.MongoDB
ou => ou.DisplayName == displayName,
GetCancellationToken(cancellationToken)
);
}
public async Task<List<IdentityRole>> GetOrganizationUnitRoles(
Guid organizationUnitId,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
var organizationUnit = await GetAsync(organizationUnitId, includeDetails, cancellationToken);
var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray();
return await DbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id)).ToListAsync(cancellationToken);
}
}
public async Task<List<IdentityRole>> GetOrganizationUnitRoles(
Guid organizationUnitId,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
var organizationUnit = await GetAsync(organizationUnitId, includeDetails, cancellationToken);
var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray();
return await DbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id)).ToListAsync(cancellationToken);
}
}
}

Loading…
Cancel
Save