From 1839095ffa355c34a5bb9ab6872439b2229926ba Mon Sep 17 00:00:00 2001 From: Jason Webb Date: Tue, 23 Jul 2024 22:53:18 -0600 Subject: [PATCH] Rolled back MediatR due to validation issue. --- .../Extensions/IQueryableExtensions.cs | 4 +-- Src/RCommon.Core/IPagedSpecification.cs | 2 +- Src/RCommon.Core/PagedSpecification.cs | 6 ++-- Src/RCommon.EfCore/Crud/EFCoreRepository.cs | 26 +++++++++++++++-- Src/RCommon.Linq2Db/Crud/Linq2DbRepository.cs | 28 +++++++++++++++++-- .../Subscribers/IAppRequest.cs | 2 +- Src/RCommon.Mediatr/RCommon.MediatR.csproj | 2 +- .../Crud/ILinqRepository.cs | 5 +++- .../Crud/LinqRepositoryBase.cs | 6 +++- 9 files changed, 65 insertions(+), 16 deletions(-) diff --git a/Src/RCommon.Core/Extensions/IQueryableExtensions.cs b/Src/RCommon.Core/Extensions/IQueryableExtensions.cs index 8584f126..280d1a86 100644 --- a/Src/RCommon.Core/Extensions/IQueryableExtensions.cs +++ b/Src/RCommon.Core/Extensions/IQueryableExtensions.cs @@ -90,11 +90,11 @@ private static MethodInfo GetLikeMethod(string value, char wildcard) return stringType.GetMethod(methodName, new Type[] { stringType }); } - public static IPaginatedList ToPaginatedList(this IQueryable source, int? pageIndex, int pageSize) + public static IPaginatedList ToPaginatedList(this IQueryable source, int pageNumber = 1, int pageSize = 10) { Guard.IsNotNegativeOrZero(pageSize, "pageSize"); - return new PaginatedList(source, pageIndex, pageSize); + return new PaginatedList(source, pageNumber, pageSize); } } diff --git a/Src/RCommon.Core/IPagedSpecification.cs b/Src/RCommon.Core/IPagedSpecification.cs index 3bd79e1a..23364dc9 100644 --- a/Src/RCommon.Core/IPagedSpecification.cs +++ b/Src/RCommon.Core/IPagedSpecification.cs @@ -9,7 +9,7 @@ namespace RCommon { public interface IPagedSpecification : ISpecification { - public int PageIndex { get; } + public int PageNumber { get; } public int PageSize { get; } public Expression> OrderByExpression { get; } diff --git a/Src/RCommon.Core/PagedSpecification.cs b/Src/RCommon.Core/PagedSpecification.cs index c6805cae..1d1a317c 100644 --- a/Src/RCommon.Core/PagedSpecification.cs +++ b/Src/RCommon.Core/PagedSpecification.cs @@ -10,16 +10,16 @@ namespace RCommon public class PagedSpecification : Specification, IPagedSpecification { public PagedSpecification(Expression> predicate, Expression> orderByExpression, - bool orderByAscending, int pageIndex, int pageSize) : base(predicate) + bool orderByAscending, int pageNumber, int pageSize) : base(predicate) { OrderByExpression = orderByExpression; OrderByAscending = orderByAscending; - PageIndex = pageIndex; + PageNumber = pageNumber; PageSize = pageSize; } public Expression> OrderByExpression { get; } - public int PageIndex { get; } + public int PageNumber { get; } public int PageSize { get; } public bool OrderByAscending { get; set; } diff --git a/Src/RCommon.EfCore/Crud/EFCoreRepository.cs b/Src/RCommon.EfCore/Crud/EFCoreRepository.cs index 957a4ebe..cec2eca2 100644 --- a/Src/RCommon.EfCore/Crud/EFCoreRepository.cs +++ b/Src/RCommon.EfCore/Crud/EFCoreRepository.cs @@ -202,11 +202,11 @@ public async override Task> FindAsync(IPagedSpecificatio { query = FindCore(specification.Predicate).OrderByDescending(specification.OrderByExpression); } - return await Task.FromResult(query.ToPaginatedList(specification.PageIndex, specification.PageSize)); + return await Task.FromResult(query.ToPaginatedList(specification.PageNumber, specification.PageSize)); } public async override Task> FindAsync(Expression> expression, Expression> orderByExpression, - bool orderByAscending, int? pageIndex, int pageSize = 1, + bool orderByAscending, int pageNumber = 1, int pageSize = 1, CancellationToken token = default) { IQueryable query; @@ -218,7 +218,27 @@ public async override Task> FindAsync(Expression FindQuery(Expression> expression, Expression> orderByExpression, + bool orderByAscending, int pageNumber = 1, int pageSize = 0) + { + IQueryable query; + if (orderByAscending) + { + query = FindCore(expression).OrderBy(orderByExpression); + } + else + { + query = FindCore(expression).OrderByDescending(orderByExpression); + } + return query.Skip((pageNumber - 1) * pageSize).Take(pageSize); + } + + public override IQueryable FindQuery(IPagedSpecification specification) + { + return this.FindQuery(specification.Predicate, specification.OrderByExpression, + specification.OrderByAscending, specification.PageNumber, specification.PageSize); } public override async Task FindSingleOrDefaultAsync(Expression> expression, CancellationToken token = default) diff --git a/Src/RCommon.Linq2Db/Crud/Linq2DbRepository.cs b/Src/RCommon.Linq2Db/Crud/Linq2DbRepository.cs index 573baf54..08b2b0ca 100644 --- a/Src/RCommon.Linq2Db/Crud/Linq2DbRepository.cs +++ b/Src/RCommon.Linq2Db/Crud/Linq2DbRepository.cs @@ -16,6 +16,7 @@ using RCommon; using RCommon.Persistence.Crud; using RCommon.Persistence.Transactions; +using LinqToDB.Linq; namespace RCommon.Persistence.Linq2Db.Crud { @@ -184,11 +185,11 @@ public async override Task> FindAsync(IPagedSpecificatio { query = FindCore(specification.Predicate).OrderByDescending(specification.OrderByExpression); } - return await Task.FromResult(query.ToPaginatedList(specification.PageIndex, specification.PageSize)); + return await Task.FromResult(query.ToPaginatedList(specification.PageNumber, specification.PageSize)); } public async override Task> FindAsync(Expression> expression, Expression> orderByExpression, - bool orderByAscending, int? pageIndex, int pageSize = 1, + bool orderByAscending, int pageNumber = 1, int pageSize = 1, CancellationToken token = default) { IQueryable query; @@ -200,7 +201,28 @@ public async override Task> FindAsync(Expression FindQuery(Expression> expression, Expression> orderByExpression, + bool orderByAscending, int pageNumber = 1, int pageSize = 0) + { + IQueryable query; + if (orderByAscending) + { + query = FindCore(expression).OrderBy(orderByExpression); + } + else + { + query = FindCore(expression).OrderByDescending(orderByExpression); + } + return query.Skip((pageNumber - 1) * pageSize).Take(pageSize); + } + + public override IQueryable FindQuery(IPagedSpecification specification) + { + return this.FindQuery(specification.Predicate, specification.OrderByExpression, + specification.OrderByAscending, specification.PageNumber, specification.PageSize); } public async override Task FindSingleOrDefaultAsync(Expression> expression, CancellationToken token = default) diff --git a/Src/RCommon.Mediator/Subscribers/IAppRequest.cs b/Src/RCommon.Mediator/Subscribers/IAppRequest.cs index d47b4ef4..70a658d5 100644 --- a/Src/RCommon.Mediator/Subscribers/IAppRequest.cs +++ b/Src/RCommon.Mediator/Subscribers/IAppRequest.cs @@ -11,7 +11,7 @@ public interface IAppRequest } - public interface IAppRequest + public interface IAppRequest { } diff --git a/Src/RCommon.Mediatr/RCommon.MediatR.csproj b/Src/RCommon.Mediatr/RCommon.MediatR.csproj index 92c2cdf0..701456b2 100644 --- a/Src/RCommon.Mediatr/RCommon.MediatR.csproj +++ b/Src/RCommon.Mediatr/RCommon.MediatR.csproj @@ -7,7 +7,7 @@ - + diff --git a/Src/RCommon.Persistence/Crud/ILinqRepository.cs b/Src/RCommon.Persistence/Crud/ILinqRepository.cs index 8c0d888b..7ea80f9d 100644 --- a/Src/RCommon.Persistence/Crud/ILinqRepository.cs +++ b/Src/RCommon.Persistence/Crud/ILinqRepository.cs @@ -17,9 +17,12 @@ public interface ILinqRepository: IQueryable, IReadOnlyReposit { IQueryable FindQuery(ISpecification specification); IQueryable FindQuery(Expression> expression); + IQueryable FindQuery(Expression> expression, Expression> orderByExpression, + bool orderByAscending, int pageNumber = 1, int pageSize = 0); + IQueryable FindQuery(IPagedSpecification specification); Task> FindAsync(Expression> expression, Expression> orderByExpression, - bool orderByAscending, int? pageIndex, int pageSize = 0, + bool orderByAscending, int pageNumber = 1, int pageSize = 0, CancellationToken token = default); Task> FindAsync(IPagedSpecification specification, CancellationToken token = default); diff --git a/Src/RCommon.Persistence/Crud/LinqRepositoryBase.cs b/Src/RCommon.Persistence/Crud/LinqRepositoryBase.cs index a5ca8eea..13622add 100644 --- a/Src/RCommon.Persistence/Crud/LinqRepositoryBase.cs +++ b/Src/RCommon.Persistence/Crud/LinqRepositoryBase.cs @@ -137,10 +137,14 @@ public IEnumerable Query(ISpecification specification) public abstract Task AnyAsync(ISpecification specification, CancellationToken token = default); public abstract Task> FindAsync(Expression> expression, Expression> orderByExpression, - bool orderByAscending, int? pageIndex, int pageSize = 0, + bool orderByAscending, int pageNumber = 1, int pageSize = 0, CancellationToken token = default); public abstract Task> FindAsync(IPagedSpecification specification, CancellationToken token = default); + public abstract IQueryable FindQuery(Expression> expression, Expression> orderByExpression, + bool orderByAscending, int pageNumber = 1, int pageSize = 0); + public abstract IQueryable FindQuery(IPagedSpecification specification); + public abstract IEagerLoadableQueryable Include(Expression> path); public abstract IEagerLoadableQueryable ThenInclude(Expression> path);