Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Minor changes Pagelist
KrzysztofPajak5e02d1528ec6
diff --git a/src/Core/Grand.Domain/Data/PagedList.cs b/src/Core/Grand.Domain/Data/PagedList.csnew file mode 100644index 000000000..db7c6b470--- /dev/null+++ b/src/Core/Grand.Domain/Data/PagedList.cs@@ -0,0 +1,98 @@+using MongoDB.Driver;+using MongoDB.Driver.Linq;+using System;+using System.Collections.Generic;+using System.Linq;+using System.Threading.Tasks;++namespace Grand.Domain+{+ public partial class PagedList<T> : List<T>, IPagedList<T>+ {+ private async Task InitializeAsync(IMongoQueryable<T> source, int pageIndex, int pageSize, int? totalCount = null)+ {+ if (source == null)+ throw new ArgumentNullException(nameof(source));+ if (pageSize <= 0)+ pageSize = 1;++ TotalCount = totalCount ?? await source.CountAsync();+ source = totalCount == null ? source.Skip(pageIndex * pageSize).Take(pageSize) : source;+ AddRange(source);++ if (pageSize > 0)+ {+ TotalPages = TotalCount / pageSize;+ if (TotalCount % pageSize > 0)+ TotalPages++;+ }++ PageSize = pageSize;+ PageIndex = pageIndex;+ }++ private async Task InitializeAsync(IMongoCollection<T> source, FilterDefinition<T> filterdefinition, SortDefinition<T> sortdefinition, int pageIndex, int pageSize, FindOptions findOptions = null)+ {+ TotalCount = (int)await source.CountDocumentsAsync(filterdefinition);++ AddRange(await source.Find(filterdefinition, findOptions).Sort(sortdefinition).Skip(pageIndex * pageSize).Limit(pageSize).ToListAsync());+ if (pageSize > 0)+ {+ TotalPages = TotalCount / pageSize;+ if (TotalCount % pageSize > 0)+ TotalPages++;+ }+ PageSize = pageSize;+ PageIndex = pageIndex;+ }++ private async Task InitializeAsync(IAggregateFluent<T> source, int pageIndex, int pageSize)+ {+ var range = source.Skip(pageIndex * pageSize).Limit(pageSize + 1).ToList();+ int total = range.Count > pageSize ? range.Count : pageSize;+ TotalCount = (await source.ToListAsync()).Count;+ if (pageSize > 0)+ TotalPages = total / pageSize;++ if (total % pageSize > 0)+ TotalPages++;++ PageSize = pageSize;+ PageIndex = pageIndex;+ AddRange(range.Take(pageSize));+ }++ public static async Task<PagedList<T>> Create(IMongoCollection<T> source, FilterDefinition<T> filterdefinition, SortDefinition<T> sortdefinition, int pageIndex, int pageSize, FindOptions findOptions = null)+ {+ var pagelist = new PagedList<T>();+ await pagelist.InitializeAsync(source, filterdefinition, sortdefinition, pageIndex, pageSize, findOptions);+ return pagelist;+ }+ public static async Task<PagedList<T>> Create(IQueryable<T> source, FilterDefinition<T> filterdefinition, SortDefinition<T> sortdefinition, int pageIndex, int pageSize, FindOptions findOptions = null)+ {+ var pagelist = new PagedList<T>();+ await pagelist.InitializeAsync((IMongoCollection<T>)source, filterdefinition, sortdefinition, pageIndex, pageSize, findOptions);+ return pagelist;+ }++ public static async Task<PagedList<T>> Create(IQueryable<T> source, int pageIndex, int pageSize, FindOptions findOptions = null)+ {+ var pagelist = new PagedList<T>();+ await pagelist.InitializeAsync((IMongoQueryable<T>)source, pageIndex, pageSize);+ return pagelist;+ }++ public static async Task<PagedList<T>> Create(IMongoQueryable<T> source, int pageIndex, int pageSize)+ {+ var pagelist = new PagedList<T>();+ await pagelist.InitializeAsync(source, pageIndex, pageSize);+ return pagelist;+ }+ public static async Task<PagedList<T>> Create(IAggregateFluent<T> source, int pageIndex, int pageSize)+ {+ var pagelist = new PagedList<T>();+ await pagelist.InitializeAsync(source, pageIndex, pageSize);+ return pagelist;+ }+ }+}diff --git a/src/Core/Grand.Domain/PagedList.cs b/src/Core/Grand.Domain/PagedList.csindex 5a37425d1..b8745f0bb 100644--- a/src/Core/Grand.Domain/PagedList.cs+++ b/src/Core/Grand.Domain/PagedList.cs@@ -1,9 +1,6 @@-using MongoDB.Driver;-using MongoDB.Driver.Linq;-using System;+using System;using System.Collections.Generic;using System.Linq;-using System.Threading.Tasks;namespace Grand.Domain{@@ -12,60 +9,8 @@ namespace Grand.Domain/// </summary>/// <typeparam name="T">T</typeparam>[Serializable]- public class PagedList<T> : List<T>, IPagedList<T>+ public partial class PagedList<T> : List<T>, IPagedList<T>{- private async Task InitializeAsync(IMongoQueryable<T> source, int pageIndex, int pageSize, int? totalCount = null)- {- if (source == null)- throw new ArgumentNullException(nameof(source));- if (pageSize <= 0)- pageSize = 1;-- TotalCount = totalCount ?? await source.CountAsync();- source = totalCount == null ? source.Skip(pageIndex * pageSize).Take(pageSize) : source;- AddRange(source);-- if (pageSize > 0)- {- TotalPages = TotalCount / pageSize;- if (TotalCount % pageSize > 0)- TotalPages++;- }-- PageSize = pageSize;- PageIndex = pageIndex;- }-- private async Task InitializeAsync(IMongoCollection<T> source, FilterDefinition<T> filterdefinition,SortDefinition<T> sortdefinition, int pageIndex, int pageSize, FindOptions findOptions = null)- {- TotalCount = (int) await source.CountDocumentsAsync(filterdefinition);-- AddRange(await source.Find(filterdefinition, findOptions).Sort(sortdefinition).Skip(pageIndex * pageSize).Limit(pageSize).ToListAsync());- if (pageSize > 0)- {- TotalPages = TotalCount / pageSize;- if (TotalCount % pageSize > 0)- TotalPages++;- }- PageSize = pageSize;- PageIndex = pageIndex;- }-- private async Task InitializeAsync(IAggregateFluent<T> source, int pageIndex, int pageSize)- {- var range = source.Skip(pageIndex * pageSize).Limit(pageSize + 1).ToList();- int total = range.Count > pageSize ? range.Count : pageSize;- TotalCount = (await source.ToListAsync()).Count;- if (pageSize > 0)- TotalPages = total / pageSize;-- if (total % pageSize > 0)- TotalPages++;-- PageSize = pageSize;- PageIndex = pageIndex;- AddRange(range.Take(pageSize));- }private void Initialize(IEnumerable<T> source, int pageIndex, int pageSize, int? totalCount = null){@@ -90,39 +35,6 @@ namespace Grand.DomainAddRange(source);}- public static async Task<PagedList<T>> Create(IMongoCollection<T> source, FilterDefinition<T> filterdefinition, SortDefinition<T> sortdefinition, int pageIndex, int pageSize, FindOptions findOptions = null)- {- var pagelist = new PagedList<T>();- await pagelist.InitializeAsync(source, filterdefinition, sortdefinition, pageIndex, pageSize, findOptions);- return pagelist;- }- public static async Task<PagedList<T>> Create(IQueryable<T> source, FilterDefinition<T> filterdefinition, SortDefinition<T> sortdefinition, int pageIndex, int pageSize, FindOptions findOptions = null)- {- var pagelist = new PagedList<T>();- await pagelist.InitializeAsync((IMongoCollection<T>)source, filterdefinition, sortdefinition, pageIndex, pageSize, findOptions);- return pagelist;- }-- public static async Task<PagedList<T>> Create(IQueryable<T> source, int pageIndex, int pageSize, FindOptions findOptions = null)- {- var pagelist = new PagedList<T>();- await pagelist.InitializeAsync((IMongoQueryable<T>)source, pageIndex, pageSize);- return pagelist;- }-- public static async Task<PagedList<T>> Create(IMongoQueryable<T> source, int pageIndex, int pageSize)- {- var pagelist = new PagedList<T>();- await pagelist.InitializeAsync(source, pageIndex, pageSize);- return pagelist;- }- public static async Task<PagedList<T>> Create(IAggregateFluent<T> source, int pageIndex, int pageSize)- {- var pagelist = new PagedList<T>();- await pagelist.InitializeAsync(source, pageIndex, pageSize);- return pagelist;- }-public PagedList(){}@@ -130,23 +42,21 @@ namespace Grand.Domain{Initialize(source, pageIndex, pageSize);}-+public PagedList(IEnumerable<T> source, int pageIndex, int pageSize, int totalCount){Initialize(source, pageIndex, pageSize, totalCount);- }+ }public int PageIndex { get; private set; }public int PageSize { get; private set; }public int TotalCount { get; private set; }public int TotalPages { get; private set; }- public bool HasPreviousPage- {+ public bool HasPreviousPage {get { return (PageIndex > 0); }}- public bool HasNextPage- {+ public bool HasNextPage {get { return (PageIndex + 1 < TotalPages); }}}