-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
131 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...YUN.Abp.Identity.Application/LINGYUN/Abp/Identity/OrganizationUnitGetListSpecification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../identity/LINGYUN.Abp.Identity.Domain/LINGYUN/Abp/Identity/IOrganizationUnitRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
32 changes: 32 additions & 0 deletions
32
.../identity/LINGYUN.Abp.Identity.Domain/System/Linq/Expressions/ExpressionFuncExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...rameworkCore/LINGYUN/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |