Skip to content

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.

RepositoryExtensions - remove unused methods

KrzysztofPajakd62f75b81b62
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/CustomerGroupProductService.cs b/src/Business/Grand.Business.Catalog/Services/Products/CustomerGroupProductService.cs
index ad8728252..a6c5b883c 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/CustomerGroupProductService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/CustomerGroupProductService.cs
@@ -109,11 +109,11 @@ namespace Grand.Business.Catalog.Services.Products
/// <param name="customerGroupId">Customer group id</param>
/// <param name="productId">Product id</param>
/// <returns>Customer group product</returns>
- public virtual Task<CustomerGroupProduct> GetCustomerGroupProduct(string customerGroupId, string productId)
+ public virtual async Task<CustomerGroupProduct> GetCustomerGroupProduct(string customerGroupId, string productId)
{
- return _customerGroupProductRepository.Table
+ return await Task.FromResult(_customerGroupProductRepository.Table
.Where(x => x.CustomerGroupId == customerGroupId && x.ProductId == productId)
- .OrderBy(x => x.DisplayOrder).FirstOrDefaultAsync2();
+ .OrderBy(x => x.DisplayOrder).FirstOrDefault());
}
/// <summary>
@@ -121,14 +121,14 @@ namespace Grand.Business.Catalog.Services.Products
/// </summary>
/// <param name="Id">id</param>
/// <returns>Customer group product</returns>
- public virtual Task<CustomerGroupProduct> GetCustomerGroupProductById(string id)
+ public virtual async Task<CustomerGroupProduct> GetCustomerGroupProductById(string id)
{
var query = from cr in _customerGroupProductRepository.Table
where cr.Id == id
orderby cr.DisplayOrder
select cr;
- return query.FirstOrDefaultAsync2();
+ return await Task.FromResult(query.FirstOrDefault());
}
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/ProductTagService.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductTagService.cs
index 81ee9391f..50cece10f 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/ProductTagService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/ProductTagService.cs
@@ -93,8 +93,7 @@ namespace Grand.Business.Catalog.Services.Products
{
return await _cacheBase.GetAsync(CacheKey.PRODUCTTAG_ALL_KEY, async () =>
{
- var query = _productTagRepository.Table;
- return await query.ToListAsync2();
+ return await Task.FromResult(_productTagRepository.Table.ToList());
});
}
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/OrderTagService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/OrderTagService.cs
index d7c0c83d6..e02fc5fd1 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/OrderTagService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/OrderTagService.cs
@@ -75,8 +75,7 @@ namespace Grand.Business.Checkout.Services.Orders
/// <returns>Order tags</returns>
public virtual async Task<IList<OrderTag>> GetAllOrderTags()
{
- var query = _orderTagRepository.Table;
- return await query.ToListAsync2();
+ return await Task.FromResult(_orderTagRepository.Table.ToList());
}
/// <summary>
diff --git a/src/Business/Grand.Business.Common/Services/Directory/SearchTermService.cs b/src/Business/Grand.Business.Common/Services/Directory/SearchTermService.cs
index 6f2543a6e..1fc4c2769 100644
--- a/src/Business/Grand.Business.Common/Services/Directory/SearchTermService.cs
+++ b/src/Business/Grand.Business.Common/Services/Directory/SearchTermService.cs
@@ -76,7 +76,7 @@ namespace Grand.Business.Common.Services.Directory
where st.Keyword == keyword && st.StoreId == storeId
orderby st.Id
select st;
- return await query.FirstOrDefaultAsync2();
+ return await Task.FromResult(query.FirstOrDefault());
}
/// <summary>
diff --git a/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs b/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs
index c59fded5c..2e4d992d0 100644
--- a/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs
+++ b/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs
@@ -118,7 +118,7 @@ namespace Grand.Business.Common.Services.Security
orderby pr.Id
select pr;
- return await query.FirstOrDefaultAsync2();
+ return await Task.FromResult(query.FirstOrDefault());
}
/// <summary>
diff --git a/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs b/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs
index 34041670b..97dfc1514 100644
--- a/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs
+++ b/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs
@@ -55,8 +55,7 @@ namespace Grand.Business.Common.Services.Seo
string key = string.Format(CacheKey.URLEntity_ALL_KEY);
return await _cacheBase.GetAsync(key, async () =>
{
- var query = _urlEntityRepository.Table;
- return await query.ToListAsync2();
+ return await Task.FromResult(_urlEntityRepository.Table.ToList());
});
}
@@ -133,7 +132,7 @@ namespace Grand.Business.Common.Services.Seo
where ur.Slug == slug
orderby ur.IsActive
select ur;
- return await query.FirstOrDefaultAsync2();
+ return await Task.FromResult(query.FirstOrDefault());
}
/// <summary>
diff --git a/src/Business/Grand.Business.Customers/Services/CustomerService.cs b/src/Business/Grand.Business.Customers/Services/CustomerService.cs
index b186ded64..422bedffa 100644
--- a/src/Business/Grand.Business.Customers/Services/CustomerService.cs
+++ b/src/Business/Grand.Business.Customers/Services/CustomerService.cs
@@ -165,7 +165,7 @@ namespace Grand.Business.Customers.Services
/// <param name="storeId">Store ident</param>
/// <param name="salesEmployeeId">Sales employee ident</param>
/// <returns>Int</returns>
- public virtual Task<int> GetCountOnlineShoppingCart(DateTime lastActivityFromUtc, string storeId = "", string salesEmployeeId = "")
+ public virtual async Task<int> GetCountOnlineShoppingCart(DateTime lastActivityFromUtc, string storeId = "", string salesEmployeeId = "")
{
var query = from p in _customerRepository.Table
select p;
@@ -180,7 +180,7 @@ namespace Grand.Business.Customers.Services
if (!string.IsNullOrEmpty(salesEmployeeId))
query = query.Where(c => c.SeId == salesEmployeeId);
- return query.CountAsync2();
+ return await Task.FromResult(query.Count());
}
/// <summary>
diff --git a/src/Business/Grand.Business.Marketing/Services/Contacts/PopupService.cs b/src/Business/Grand.Business.Marketing/Services/Contacts/PopupService.cs
index b76876526..bea0dd358 100644
--- a/src/Business/Grand.Business.Marketing/Services/Contacts/PopupService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Contacts/PopupService.cs
@@ -52,7 +52,7 @@ namespace Grand.Business.Marketing.Services.Contacts
where c.CustomerId == customerId
orderby c.CreatedOnUtc
select c;
- return await query.FirstOrDefaultAsync2();
+ return await Task.FromResult(query.FirstOrDefault());
}
public virtual async Task MovepopupToArchive(string id, string customerId)
diff --git a/src/Business/Grand.Business.Marketing/Services/Customers/CustomerActionEventService.cs b/src/Business/Grand.Business.Marketing/Services/Customers/CustomerActionEventService.cs
index 14e070f68..95bcd7604 100644
--- a/src/Business/Grand.Business.Marketing/Services/Customers/CustomerActionEventService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Customers/CustomerActionEventService.cs
@@ -48,9 +48,9 @@ namespace Grand.Business.Marketing.Services.Customers
protected async Task<IList<CustomerActionType>> GetAllCustomerActionType()
{
- return await _cacheBase.GetAsync(CacheKey.CUSTOMER_ACTION_TYPE, () =>
+ return await _cacheBase.GetAsync(CacheKey.CUSTOMER_ACTION_TYPE, async () =>
{
- return _customerActionTypeRepository.Table.ToListAsync2();
+ return await Task.FromResult(_customerActionTypeRepository.Table.ToList());
});
}
diff --git a/src/Business/Grand.Business.Marketing/Services/Customers/CustomerActionService.cs b/src/Business/Grand.Business.Marketing/Services/Customers/CustomerActionService.cs
index a13b4c304..2bdbd2b0a 100644
--- a/src/Business/Grand.Business.Marketing/Services/Customers/CustomerActionService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Customers/CustomerActionService.cs
@@ -61,8 +61,7 @@ namespace Grand.Business.Marketing.Services.Customers
/// <returns>Customer actions</returns>
public virtual async Task<IList<CustomerAction>> GetCustomerActions()
{
- var query = _customerActionRepository.Table;
- return await query.ToListAsync2();
+ return await Task.FromResult(_customerActionRepository.Table.ToList());
}
/// <summary>
@@ -118,8 +117,7 @@ namespace Grand.Business.Marketing.Services.Customers
public virtual async Task<IList<CustomerActionType>> GetCustomerActionType()
{
- var query = _customerActionTypeRepository.Table;
- return await query.ToListAsync2();
+ return await Task.FromResult(_customerActionTypeRepository.Table.ToList());
}
public virtual async Task<IPagedList<CustomerActionHistory>> GetAllCustomerActionHistory(string customerActionId, int pageIndex = 0, int pageSize = 2147483647)
diff --git a/src/Business/Grand.Business.Marketing/Services/Customers/CustomerTagService.cs b/src/Business/Grand.Business.Marketing/Services/Customers/CustomerTagService.cs
index 5e6551377..cbd33dbf2 100644
--- a/src/Business/Grand.Business.Marketing/Services/Customers/CustomerTagService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Customers/CustomerTagService.cs
@@ -86,8 +86,7 @@ namespace Grand.Business.Marketing.Services.Customers
/// <returns>Customer tags</returns>
public virtual async Task<IList<CustomerTag>> GetAllCustomerTags()
{
- var query = _customerTagRepository.Table;
- return await query.ToListAsync2();
+ return await Task.FromResult(_customerTagRepository.Table.ToList());
}
/// <summary>
@@ -215,13 +214,13 @@ namespace Grand.Business.Marketing.Services.Customers
/// <param name="customerTagId">Customer tag id</param>
/// <param name="productId">Product id</param>
/// <returns>Customer tag product</returns>
- public virtual Task<CustomerTagProduct> GetCustomerTagProduct(string customerTagId, string productId)
+ public virtual async Task<CustomerTagProduct> GetCustomerTagProduct(string customerTagId, string productId)
{
var query = from cr in _customerTagProductRepository.Table
where cr.CustomerTagId == customerTagId && cr.ProductId == productId
orderby cr.DisplayOrder
select cr;
- return query.FirstOrDefaultAsync2();
+ return await Task.FromResult(query.FirstOrDefault());
}
/// <summary>
diff --git a/src/Business/Grand.Business.Marketing/Services/Newsletters/NewsLetterSubscriptionService.cs b/src/Business/Grand.Business.Marketing/Services/Newsletters/NewsLetterSubscriptionService.cs
index e1a13b51c..ca3005740 100644
--- a/src/Business/Grand.Business.Marketing/Services/Newsletters/NewsLetterSubscriptionService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Newsletters/NewsLetterSubscriptionService.cs
@@ -179,7 +179,7 @@ namespace Grand.Business.Marketing.Services.Newsteletters
orderby nls.Id
select nls;
- return await newsLetterSubscriptions.FirstOrDefaultAsync2();
+ return await Task.FromResult(newsLetterSubscriptions.FirstOrDefault());
}
/// <summary>
@@ -200,7 +200,7 @@ namespace Grand.Business.Marketing.Services.Newsteletters
orderby nls.Id
select nls;
- return await newsLetterSubscriptions.FirstOrDefaultAsync2();
+ return await Task.FromResult(newsLetterSubscriptions.FirstOrDefault());
}
/// <summary>
@@ -218,7 +218,7 @@ namespace Grand.Business.Marketing.Services.Newsteletters
orderby nls.Id
select nls;
- return await newsLetterSubscriptions.FirstOrDefaultAsync2();
+ return await Task.FromResult(newsLetterSubscriptions.FirstOrDefault());
}
/// <summary>
diff --git a/src/Business/Grand.Business.Marketing/Services/Newsletters/NewsletterCategoryService.cs b/src/Business/Grand.Business.Marketing/Services/Newsletters/NewsletterCategoryService.cs
index 6b125755c..59614abc3 100644
--- a/src/Business/Grand.Business.Marketing/Services/Newsletters/NewsletterCategoryService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Newsletters/NewsletterCategoryService.cs
@@ -92,7 +92,7 @@ namespace Grand.Business.Marketing.Services.Newsteletters
/// <returns>NewsletterCategories</returns>
public virtual async Task<IList<NewsletterCategory>> GetAllNewsletterCategory()
{
- return await _newsletterCategoryRepository.Table.ToListAsync2();
+ return await Task.FromResult(_newsletterCategoryRepository.Table.ToList());
}
/// <summary>
diff --git a/src/Business/Grand.Business.System/Services/BackgroundServices/ScheduleTasks/ScheduleTaskService.cs b/src/Business/Grand.Business.System/Services/BackgroundServices/ScheduleTasks/ScheduleTaskService.cs
index 490812508..dd13ef50d 100644
--- a/src/Business/Grand.Business.System/Services/BackgroundServices/ScheduleTasks/ScheduleTaskService.cs
+++ b/src/Business/Grand.Business.System/Services/BackgroundServices/ScheduleTasks/ScheduleTaskService.cs
@@ -43,13 +43,13 @@ namespace Grand.Business.System.Services.BackgroundServices.ScheduleTasks
/// </summary>
/// <param name="type">Task type</param>
/// <returns>Task</returns>
- public virtual Task<ScheduleTask> GetTaskByType(string type)
+ public virtual async Task<ScheduleTask> GetTaskByType(string type)
{
if (string.IsNullOrWhiteSpace(type))
- return Task.FromResult<ScheduleTask>(null);
+ return null;
var query = _taskRepository.Table.Where(st => st.Type == type).OrderByDescending(t => t.Id);
- return query.FirstOrDefaultAsync2();
+ return await Task.FromResult(query.FirstOrDefault());
}
/// <summary>
@@ -59,7 +59,7 @@ namespace Grand.Business.System.Services.BackgroundServices.ScheduleTasks
/// <returns>Tasks</returns>
public virtual async Task<IList<ScheduleTask>> GetAllTasks()
{
- return await _taskRepository.Table.ToListAsync2();
+ return await Task.FromResult(_taskRepository.Table.ToList());
}
/// <summary>
diff --git a/src/Core/Grand.Domain/Data/RepositoryExtensions.cs b/src/Core/Grand.Domain/Data/RepositoryExtensions.cs
index 063e40717..01e7c6e85 100644
--- a/src/Core/Grand.Domain/Data/RepositoryExtensions.cs
+++ b/src/Core/Grand.Domain/Data/RepositoryExtensions.cs
@@ -13,28 +13,10 @@ namespace Grand.Domain.Data
return ((IMongoQueryable<T>)query).ToListAsync();
}
- public static Task<List<T>> ToListAsync2<T>(this IMongoQueryable<T> query)
- {
- return query.ToListAsync();
- }
-
- public static Task<T> FirstOrDefaultAsync2<T>(this IMongoQueryable<T> query)
- {
- return query.FirstOrDefaultAsync();
- }
-
- public static Task<T> FirstOrDefaultAsync2<T>(this IOrderedQueryable<T> query)
- {
- return ((IMongoQueryable<T>)query).FirstOrDefaultAsync();
- }
public static Task<T> FirstOrDefaultAsync2<T>(this IQueryable<T> query)
{
return ((IMongoQueryable<T>)query).FirstOrDefaultAsync();
}
-
- public static Task<int> CountAsync2<T>(this IQueryable<T> query)
- {
- return ((IMongoQueryable<T>)query).CountAsync();
- }
+
}
}
diff --git a/src/Core/Grand.Domain/PagedList.cs b/src/Core/Grand.Domain/PagedList.cs
index c072d4049..17553eecc 100644
--- a/src/Core/Grand.Domain/PagedList.cs
+++ b/src/Core/Grand.Domain/PagedList.cs
@@ -1,5 +1,4 @@
-using Grand.Domain.Data;
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@@ -49,14 +48,15 @@ namespace Grand.Domain
{
Initialize(source, pageIndex, pageSize, totalCount);
}
- private async Task InitializeAsync(IQueryable<T> source, int pageIndex, int pageSize, int? totalCount = null)
+
+ private Task InitializeAsync(IQueryable<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.CountAsync2();
+ TotalCount = totalCount ?? source.Count();
source = totalCount == null ? source.Skip(pageIndex * pageSize).Take(pageSize) : source;
AddRange(source);
@@ -69,6 +69,7 @@ namespace Grand.Domain
PageSize = pageSize;
PageIndex = pageIndex;
+ return Task.CompletedTask;
}
public static async Task<PagedList<T>> Create(IQueryable<T> source, int pageIndex, int pageSize)