Skip to content

Commit

Permalink
Merge pull request #873 from colinin/fix-identity
Browse files Browse the repository at this point in the history
fix(identity): fix issues #853
  • Loading branch information
colinin committed Sep 8, 2023
2 parents f6c95ad + 889cd8a commit 674d463
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 4 deletions.
4 changes: 2 additions & 2 deletions aspnet-core/LINGYUN.MicroService.All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cli", "cli", "{59627844-A66
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Cli", "modules\cli\LINGYUN.Abp.Cli\LINGYUN.Abp.Cli.csproj", "{2F49E870-DAE2-4D89-98CA-46BBD91C68E2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.OssManagement.FileSystem.Imaging", "modules\oss-management\LINGYUN.Abp.OssManagement.FileSystem.Imaging\LINGYUN.Abp.OssManagement.FileSystem.Imaging.csproj", "{6C8489F4-68B5-4CBC-8463-010C71C23245}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.OssManagement.FileSystem.Imaging", "modules\oss-management\LINGYUN.Abp.OssManagement.FileSystem.Imaging\LINGYUN.Abp.OssManagement.FileSystem.Imaging.csproj", "{6C8489F4-68B5-4CBC-8463-010C71C23245}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp", "modules\oss-management\LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp\LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp.csproj", "{5177C729-7666-4A6C-9D54-D7E5DEF0E857}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp", "modules\oss-management\LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp\LINGYUN.Abp.OssManagement.FileSystem.Imaging.ImageSharp.csproj", "{5177C729-7666-4A6C-9D54-D7E5DEF0E857}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,12 @@ public async virtual Task<ListResultDto<OrganizationUnitDto>> GetAllListAsync()

public async virtual Task<PagedResultDto<OrganizationUnitDto>> GetListAsync(OrganizationUnitGetByPagedDto input)
{
var origanizationUnitCount = await OrganizationUnitRepository.GetCountAsync();
var specification = new OrganizationUnitGetListSpecification(input);

var origanizationUnitCount = await OrganizationUnitRepository.GetCountAsync(specification);

var origanizationUnits = await OrganizationUnitRepository
.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, false);
.GetListAsync(specification, input.Sorting, input.MaxResultCount, input.SkipCount, false);

return new PagedResultDto<OrganizationUnitDto>(origanizationUnitCount,
ObjectMapper.Map<List<OrganizationUnit>, List<OrganizationUnitDto>>(origanizationUnits));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Linq.Expressions;
using Volo.Abp.Identity;
using Volo.Abp.Specifications;

namespace LINGYUN.Abp.Identity;
public class OrganizationUnitGetListSpecification : Specification<OrganizationUnit>
{
protected OrganizationUnitGetByPagedDto Input { get; }
public OrganizationUnitGetListSpecification(OrganizationUnitGetByPagedDto input)
{
Input = input;
}

public override Expression<Func<OrganizationUnit, bool>> ToExpression()
{
Expression<Func<OrganizationUnit, bool>> expression = _ => true;

return expression
.AndIf(!Input.Filter.IsNullOrWhiteSpace(), x =>
x.DisplayName.Contains(Input.Filter) || x.Code.Contains(Input.Filter));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Identity;
using Volo.Abp.Specifications;

namespace LINGYUN.Abp.Identity;

public interface IOrganizationUnitRepository : Volo.Abp.Identity.IOrganizationUnitRepository
{
Task<int> GetCountAsync(
ISpecification<OrganizationUnit> specification,
CancellationToken cancellationToken = default);

Task<List<OrganizationUnit>> GetListAsync(
ISpecification<OrganizationUnit> specification,
string sorting = nameof(OrganizationUnit.Code),
int maxResultCount = 10,
int skipCount = 0,
bool includeDetails = false,
CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Volo.Abp.Specifications;

namespace System.Linq.Expressions;

public static class ExpressionFuncExtensions
{
public static Expression<Func<T, bool>> AndIf<T>(
this Expression<Func<T, bool>> first,
bool condition,
Expression<Func<T, bool>> second)
{
if (condition)
{
return ExpressionFuncExtender.And(first, second);
}

return first;
}

public static Expression<Func<T, bool>> OrIf<T>(
this Expression<Func<T, bool>> first,
bool condition,
Expression<Func<T, bool>> second)
{
if (condition)
{
return ExpressionFuncExtender.Or(first, second);
}

return first;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
{
options.AddRepository<IdentityRole, EfCoreIdentityRoleRepository>();
options.AddRepository<IdentityUser, EfCoreIdentityUserRepository>();
options.AddRepository<OrganizationUnit, EfCoreOrganizationUnitRepository>();
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Identity;
using Volo.Abp.Identity.EntityFrameworkCore;
using Volo.Abp.Specifications;

namespace LINGYUN.Abp.Identity.EntityFrameworkCore;

public class EfCoreOrganizationUnitRepository : Volo.Abp.Identity.EntityFrameworkCore.EfCoreOrganizationUnitRepository, IOrganizationUnitRepository
{
public EfCoreOrganizationUnitRepository(
IDbContextProvider<IIdentityDbContext> dbContextProvider)
: base(dbContextProvider)
{
}

public async virtual Task<int> GetCountAsync(
ISpecification<OrganizationUnit> specification,
CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.Where(specification.ToExpression())
.CountAsync(GetCancellationToken(cancellationToken));
}

public async virtual Task<List<OrganizationUnit>> GetListAsync(
ISpecification<OrganizationUnit> specification,
string sorting = nameof(OrganizationUnit.Code),
int maxResultCount = 10,
int skipCount = 0,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.Where(specification.ToExpression())
.OrderBy(sorting)
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
}

0 comments on commit 674d463

Please sign in to comment.