From 6a04a6a270bc8dcd5c1e140b77d3ac18193e870d Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Sun, 9 Aug 2026 00:40:25 +0330 Subject: [PATCH] feat(package): enhance pagination logic in GetCustomerPackagePurchaseRollupQueryHandler - Updated pagination handling to allow for exporting all results when PageSize is set to 0. - Adjusted page size and number calculations to accommodate the new export functionality. - Improved clarity in pagination logic by distinguishing between export and paginated results. --- ...stomerPackagePurchaseRollupQueryHandler.cs | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/CMSMicroservice.Application/UserPackagePurchaseCQ/Queries/GetCustomerPackagePurchaseRollup/GetCustomerPackagePurchaseRollupQueryHandler.cs b/src/CMSMicroservice.Application/UserPackagePurchaseCQ/Queries/GetCustomerPackagePurchaseRollup/GetCustomerPackagePurchaseRollupQueryHandler.cs index 5fc0e91..ca2e401 100644 --- a/src/CMSMicroservice.Application/UserPackagePurchaseCQ/Queries/GetCustomerPackagePurchaseRollup/GetCustomerPackagePurchaseRollupQueryHandler.cs +++ b/src/CMSMicroservice.Application/UserPackagePurchaseCQ/Queries/GetCustomerPackagePurchaseRollup/GetCustomerPackagePurchaseRollupQueryHandler.cs @@ -22,7 +22,9 @@ public class GetCustomerPackagePurchaseRollupQueryHandler var filter = request.Filter; var pagination = request.PaginationState ?? new PaginationState { PageNumber = 1, PageSize = 20 }; if (pagination.PageNumber < 1) pagination.PageNumber = 1; - if (pagination.PageSize < 1) pagination.PageSize = 20; + // PageSize == 0 → خروجی کامل (بدون صفحه‌بندی)، مثلاً Excel + var exportAll = pagination.PageSize == 0; + if (!exportAll && pagination.PageSize < 1) pagination.PageSize = 20; // خرید معتبر: بدون تراکنش یا تراکنش موفق var purchases = _context.UserPackagePurchases @@ -104,14 +106,18 @@ public class GetCustomerPackagePurchaseRollupQueryHandler .ToList(); var totalCount = grouped.Count; - var pageSize = pagination.PageSize; - var pageNumber = pagination.PageNumber; - var totalPage = pageSize > 0 ? (int)Math.Ceiling(totalCount / (double)pageSize) : 0; + var pageNumber = exportAll ? 1 : pagination.PageNumber; + var pageSize = exportAll ? totalCount : pagination.PageSize; + var totalPage = exportAll || pageSize <= 0 + ? (totalCount > 0 ? 1 : 0) + : (int)Math.Ceiling(totalCount / (double)pageSize); - var pageModels = grouped - .Skip((pageNumber - 1) * pageSize) - .Take(pageSize) - .ToList(); + var pageModels = exportAll + ? grouped + : grouped + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) + .ToList(); return new GetCustomerPackagePurchaseRollupResponseDto { @@ -121,8 +127,8 @@ public class GetCustomerPackagePurchaseRollupQueryHandler PageSize = pageSize, TotalCount = totalCount, TotalPage = totalPage, - HasPrevious = pageNumber > 1, - HasNext = pageNumber < totalPage + HasPrevious = !exportAll && pageNumber > 1, + HasNext = !exportAll && pageNumber < totalPage }, Models = pageModels };