7 changed files with 131 additions and 4 deletions
@ -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)); |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
@ -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; |
||||
|
} |
||||
|
} |
||||
@ -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)); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue