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.

Execute repository queries on the driver instead of blocking a thread (#776)

Krzysztof Pajak81ff8e2d8adf
diff --git a/src/Business/Grand.Business.Authentication/Services/ExternalAuthenticationService.cs b/src/Business/Grand.Business.Authentication/Services/ExternalAuthenticationService.cs
index adbc4e11a..1e9724d50 100644
--- a/src/Business/Grand.Business.Authentication/Services/ExternalAuthenticationService.cs
+++ b/src/Business/Grand.Business.Authentication/Services/ExternalAuthenticationService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Commands.Customers;
+using Grand.Business.Core.Commands.Customers;
using Grand.Business.Core.Events.Customers;
using Grand.Business.Core.Extensions;
using Grand.Business.Core.Interfaces.Authentication;
@@ -327,7 +327,7 @@ public class ExternalAuthenticationService : IExternalAuthenticationService
var query = from p in _externalAuthenticationRecordRepository.Table
where p.CustomerId == customer.Id
select p;
- return await Task.FromResult(query.ToList());
+ return await _externalAuthenticationRecordRepository.ToListAsync(query);
}
/// <summary>
diff --git a/src/Business/Grand.Business.Catalog/Services/Brands/BrandLayoutService.cs b/src/Business/Grand.Business.Catalog/Services/Brands/BrandLayoutService.cs
index 61fd12dc5..dd18e9c53 100644
--- a/src/Business/Grand.Business.Catalog/Services/Brands/BrandLayoutService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Brands/BrandLayoutService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Catalog.Brands;
+using Grand.Business.Core.Interfaces.Catalog.Brands;
using Grand.Data;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Caching;
@@ -53,7 +53,7 @@ public class BrandLayoutService : IBrandLayoutService
var query = from pt in _brandLayoutRepository.Table
orderby pt.DisplayOrder
select pt;
- return await Task.FromResult(query.ToList());
+ return await _brandLayoutRepository.ToListAsync(query);
});
}
diff --git a/src/Business/Grand.Business.Catalog/Services/Brands/BrandService.cs b/src/Business/Grand.Business.Catalog/Services/Brands/BrandService.cs
index 5b98c661d..0065024f0 100644
--- a/src/Business/Grand.Business.Catalog/Services/Brands/BrandService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Brands/BrandService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Catalog.Brands;
+using Grand.Business.Core.Interfaces.Catalog.Brands;
using Grand.Data;
using Grand.Domain;
using Grand.Domain.Catalog;
@@ -166,7 +166,7 @@ public class BrandService : IBrandService
where c.AppliedDiscounts.Any(x => x == discountId)
select c;
- return await Task.FromResult(query.ToList());
+ return await _brandRepository.ToListAsync(query);
}
#endregion
diff --git a/src/Business/Grand.Business.Catalog/Services/Categories/CategoryLayoutService.cs b/src/Business/Grand.Business.Catalog/Services/Categories/CategoryLayoutService.cs
index 152ba9350..66a99dfb9 100644
--- a/src/Business/Grand.Business.Catalog/Services/Categories/CategoryLayoutService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Categories/CategoryLayoutService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Catalog.Categories;
+using Grand.Business.Core.Interfaces.Catalog.Categories;
using Grand.Data;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Caching;
@@ -53,7 +53,7 @@ public class CategoryLayoutService : ICategoryLayoutService
var query = from pt in _categoryLayoutRepository.Table
orderby pt.DisplayOrder
select pt;
- return await Task.FromResult(query.ToList());
+ return await _categoryLayoutRepository.ToListAsync(query);
});
}
diff --git a/src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs b/src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs
index 880e315b3..744e3bed1 100644
--- a/src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs
@@ -129,7 +129,7 @@ public class CategoryService : ICategoryService
{
case true when
string.IsNullOrEmpty(CurrentStore.Id) || _accessControlConfig.IgnoreStoreLimitations:
- return await Task.FromResult(query.ToList());
+ return await _categoryRepository.ToListAsync(query);
case false:
{
//Limited to customer group (access control list)
@@ -146,7 +146,7 @@ public class CategoryService : ICategoryService
query = from p in query
where !p.LimitedToStores || p.Stores.Contains(CurrentStore.Id)
select p;
- return await Task.FromResult(query.ToList());
+ return await _categoryRepository.ToListAsync(query);
}
/// <summary>
@@ -217,7 +217,7 @@ public class CategoryService : ICategoryService
var query = _categoryRepository.Table
.Where(x => x.Published && x.ShowOnHomePage)
.OrderBy(x => x.DisplayOrder);
- var categories = await Task.FromResult(query.ToList());
+ var categories = await _categoryRepository.ToListAsync(query);
if (!showHidden)
categories = categories
.Where(c => _aclService.Authorize(c, CurrentCustomer) &&
@@ -238,7 +238,7 @@ public class CategoryService : ICategoryService
.Where(x => x.Published && x.FeaturedProductsOnHomePage)
.OrderBy(x => x.DisplayOrder);
- var categories = await Task.FromResult(query.ToList());
+ var categories = await _categoryRepository.ToListAsync(query);
if (!showHidden)
categories = categories
.Where(c => _aclService.Authorize(c, CurrentCustomer) &&
@@ -257,7 +257,7 @@ public class CategoryService : ICategoryService
.Where(x => x.Published && x.ShowOnSearchBox)
.OrderBy(x => x.SearchBoxDisplayOrder);
- var categories = (await Task.FromResult(query.ToList()))
+ var categories = (await _categoryRepository.ToListAsync(query))
.Where(c => _aclService.Authorize(c, CurrentCustomer) &&
_aclService.Authorize(c, CurrentStore.Id))
.ToList();
@@ -392,7 +392,7 @@ public class CategoryService : ICategoryService
where c.AppliedDiscounts.Any(x => x == discountId)
select c;
- return await Task.FromResult(query.ToList());
+ return await _categoryRepository.ToListAsync(query);
}
/// <summary>
diff --git a/src/Business/Grand.Business.Catalog/Services/Collections/CollectionLayoutService.cs b/src/Business/Grand.Business.Catalog/Services/Collections/CollectionLayoutService.cs
index b9ceb2a53..10f83b0d4 100644
--- a/src/Business/Grand.Business.Catalog/Services/Collections/CollectionLayoutService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Collections/CollectionLayoutService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Catalog.Collections;
+using Grand.Business.Core.Interfaces.Catalog.Collections;
using Grand.Data;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Caching;
@@ -53,7 +53,7 @@ public class CollectionLayoutService : ICollectionLayoutService
var query = from pt in _collectionLayoutRepository.Table
orderby pt.DisplayOrder
select pt;
- return await Task.FromResult(query.ToList());
+ return await _collectionLayoutRepository.ToListAsync(query);
});
}
diff --git a/src/Business/Grand.Business.Catalog/Services/Collections/CollectionService.cs b/src/Business/Grand.Business.Catalog/Services/Collections/CollectionService.cs
index 2019df160..88721efda 100644
--- a/src/Business/Grand.Business.Catalog/Services/Collections/CollectionService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Collections/CollectionService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Catalog.Collections;
+using Grand.Business.Core.Interfaces.Catalog.Collections;
using Grand.Business.Core.Interfaces.Common.Security;
using Grand.Data;
using Grand.Domain;
@@ -109,7 +109,7 @@ public class CollectionService : ICollectionService
var query = _collectionRepository.Table.Where(x => x.Published && x.FeaturedProductsOnHomePage)
.OrderBy(x => x.DisplayOrder);
- var collections = await Task.FromResult(query.ToList());
+ var collections = await _collectionRepository.ToListAsync(query);
if (!showHidden)
collections = collections
.Where(c => _aclService.Authorize(c, _contextAccessor.WorkContext.CurrentCustomer) &&
@@ -193,7 +193,7 @@ public class CollectionService : ICollectionService
where c.AppliedDiscounts.Any(x => x == discountId)
select c;
- return await Task.FromResult(query.ToList());
+ return await _collectionRepository.ToListAsync(query);
}
#endregion
diff --git a/src/Business/Grand.Business.Catalog/Services/Directory/MeasureService.cs b/src/Business/Grand.Business.Catalog/Services/Directory/MeasureService.cs
index c91719194..3168de340 100644
--- a/src/Business/Grand.Business.Catalog/Services/Directory/MeasureService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Directory/MeasureService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Catalog.Directory;
+using Grand.Business.Core.Interfaces.Catalog.Directory;
using Grand.Data;
using Grand.Domain.Directory;
using Grand.Infrastructure.Caching;
@@ -94,7 +94,7 @@ public class MeasureService : IMeasureService
var query = from md in _measureDimensionRepository.Table
orderby md.DisplayOrder
select md;
- return await Task.FromResult(query.ToList());
+ return await _measureDimensionRepository.ToListAsync(query);
});
}
@@ -250,7 +250,7 @@ public class MeasureService : IMeasureService
var query = from mw in _measureWeightRepository.Table
orderby mw.DisplayOrder
select mw;
- return await Task.FromResult(query.ToList());
+ return await _measureWeightRepository.ToListAsync(query);
});
}
@@ -391,7 +391,7 @@ public class MeasureService : IMeasureService
var query = from md in _measureUnitRepository.Table
orderby md.DisplayOrder
select md;
- return await Task.FromResult(query.ToList());
+ return await _measureUnitRepository.ToListAsync(query);
});
}
diff --git a/src/Business/Grand.Business.Catalog/Services/Directory/SearchTermService.cs b/src/Business/Grand.Business.Catalog/Services/Directory/SearchTermService.cs
index 2fa55f7ca..664a77b8b 100644
--- a/src/Business/Grand.Business.Catalog/Services/Directory/SearchTermService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Directory/SearchTermService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Catalog.Directory;
+using Grand.Business.Core.Interfaces.Catalog.Directory;
using Grand.Business.Core.Utilities.Catalog;
using Grand.Data;
using Grand.Domain;
@@ -71,7 +71,7 @@ public class SearchTermService : ISearchTermService
var query = from st in _searchTermRepository.Table
where st.Keyword == keyword && st.StoreId == storeId
select st;
- return await Task.FromResult(query.FirstOrDefault());
+ return await _searchTermRepository.FirstOrDefaultAsync(query);
}
/// <summary>
diff --git a/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountService.cs b/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountService.cs
index 3fc47a86f..2ca851f45 100644
--- a/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountService.cs
@@ -115,7 +115,7 @@ public class DiscountService : IDiscountService
query = query.OrderBy(d => d.Name);
- return await Task.FromResult(query.ToList());
+ return await _discountRepository.ToListAsync(query);
}
/// <summary>
diff --git a/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountValidationService.cs b/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountValidationService.cs
index 12eff48fb..52f6287dd 100644
--- a/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountValidationService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountValidationService.cs
@@ -237,7 +237,7 @@ public class DiscountValidationService : IDiscountValidationService
if (used.HasValue)
query = query.Where(x => x.Used == used.Value);
- var result = await Task.FromResult(query.ToList());
+ var result = await _discountCouponRepository.ToListAsync(query);
return result.Count != 0;
}
}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/AuctionService.cs b/src/Business/Grand.Business.Catalog/Services/Products/AuctionService.cs
index ad81bacfa..3d9f4d1d0 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/AuctionService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/AuctionService.cs
@@ -107,9 +107,9 @@ public class AuctionService : IAuctionService
public virtual async Task<IList<Product>> GetAuctionsToEnd()
{
- return await Task.FromResult(_productRepository.Table
+ return await _productRepository.ToListAsync(_productRepository.Table
.Where(x => x.ProductTypeId == ProductType.Auction &&
- !x.AuctionEnded && x.AvailableEndDateTimeUtc < DateTime.UtcNow).ToList());
+ !x.AuctionEnded && x.AvailableEndDateTimeUtc < DateTime.UtcNow));
}
public virtual async Task UpdateAuctionEnded(Product product, bool ended, bool endDate = false)
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/CustomerGroupProductService.cs b/src/Business/Grand.Business.Catalog/Services/Products/CustomerGroupProductService.cs
index fc1120737..65efafc48 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/CustomerGroupProductService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/CustomerGroupProductService.cs
@@ -95,10 +95,9 @@ public class CustomerGroupProductService : ICustomerGroupProductService
var key = string.Format(CacheKey.CUSTOMERGROUPSPRODUCTS_ROLE_KEY, customerGroupId);
return await _cacheBase.GetAsync(key, async () =>
{
- return await Task.FromResult(_customerGroupProductRepository
+ return (await _customerGroupProductRepository.ToListAsync(_customerGroupProductRepository
.Table.Where(x => x.CustomerGroupId == customerGroupId)
- .OrderBy(x => x.DisplayOrder)
- .ToList());
+ .OrderBy(x => x.DisplayOrder))).ToList();
});
}
@@ -110,9 +109,9 @@ public class CustomerGroupProductService : ICustomerGroupProductService
/// <returns>Customer group product</returns>
public virtual async Task<CustomerGroupProduct> GetCustomerGroupProduct(string customerGroupId, string productId)
{
- return await Task.FromResult(_customerGroupProductRepository.Table
+ return await _customerGroupProductRepository.FirstOrDefaultAsync(_customerGroupProductRepository.Table
.Where(x => x.CustomerGroupId == customerGroupId && x.ProductId == productId)
- .OrderBy(x => x.DisplayOrder).FirstOrDefault());
+ .OrderBy(x => x.DisplayOrder));
}
/// <summary>
@@ -127,7 +126,7 @@ public class CustomerGroupProductService : ICustomerGroupProductService
orderby cr.DisplayOrder
select cr;
- return await Task.FromResult(query.FirstOrDefault());
+ return await _customerGroupProductRepository.FirstOrDefaultAsync(query);
}
#endregion
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/InventoryManageService.cs b/src/Business/Grand.Business.Catalog/Services/Products/InventoryManageService.cs
index 2fbb0cf59..289127824 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/InventoryManageService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/InventoryManageService.cs
@@ -166,7 +166,7 @@ public class InventoryManageService : IInventoryManageService
where j.ProductId == product.Id && j.PositionId == shipmentItem.Id
select j.Id;
- return await Task.FromResult(query.Any());
+ return await _inventoryJournalRepository.AnyAsync(query);
}
private async Task ReverseBookedInventory(Product product, InventoryJournal inventoryJournal)
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/OutOfStockSubscriptionService.cs b/src/Business/Grand.Business.Catalog/Services/Products/OutOfStockSubscriptionService.cs
index 024342526..29c4e5b62 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/OutOfStockSubscriptionService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/OutOfStockSubscriptionService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Commands.Catalog;
+using Grand.Business.Core.Commands.Catalog;
using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Data;
using Grand.Domain;
@@ -82,7 +82,7 @@ public class OutOfStockSubscriptionService : IOutOfStockSubscriptionService
biss.WarehouseId == warehouseId
select biss;
- var outOfStockSubscriptionlist = await Task.FromResult(query.ToList());
+ var outOfStockSubscriptionlist = await _outOfStockSubscriptionRepository.ToListAsync(query);
if (attributes != null && attributes.Any())
outOfStockSubscriptionlist = outOfStockSubscriptionlist.Where(x =>
x.Attributes.All(y => attributes.Any(z => z.Key == y.Key && z.Value == y.Value))).ToList();
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/ProductLayoutService.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductLayoutService.cs
index 4b49a8433..182803bbf 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/ProductLayoutService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/ProductLayoutService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Data;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Caching;
@@ -53,7 +53,7 @@ public class ProductLayoutService : IProductLayoutService
var query = from pt in _productLayoutRepository.Table
orderby pt.DisplayOrder
select pt;
- return await Task.FromResult(query.ToList());
+ return await _productLayoutRepository.ToListAsync(query);
});
}
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/ProductReservationService.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductReservationService.cs
index 9948cfeef..d2e6f2db3 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/ProductReservationService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/ProductReservationService.cs
@@ -169,8 +169,8 @@ public class ProductReservationService : IProductReservationService
/// </returns>
public virtual async Task<IList<CustomerReservationsHelper>> GetCustomerReservationsHelpers(string customerId)
{
- return await Task.FromResult(_customerReservationsHelperRepository.Table.Where(x => x.CustomerId == customerId)
- .ToList());
+ return await _customerReservationsHelperRepository.ToListAsync(
+ _customerReservationsHelperRepository.Table.Where(x => x.CustomerId == customerId));
}
/// <summary>
@@ -182,7 +182,7 @@ public class ProductReservationService : IProductReservationService
/// </returns>
public virtual async Task<IList<CustomerReservationsHelper>> GetCustomerReservationsHelperBySciId(string sciId)
{
- return await Task.FromResult(_customerReservationsHelperRepository.Table
- .Where(x => x.ShoppingCartItemId == sciId).ToList());
+ return await _customerReservationsHelperRepository.ToListAsync(
+ _customerReservationsHelperRepository.Table.Where(x => x.ShoppingCartItemId == sciId));
}
}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs
index 18e2e17a1..71b5a4991 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Events.Catalog;
+using Grand.Business.Core.Events.Catalog;
using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Business.Core.Interfaces.Common.Security;
using Grand.Business.Core.Queries.Catalog;
@@ -65,7 +65,7 @@ public class ProductService : IProductService
var query = _productRepository.Table.Where(x => x.Published && x.ShowOnHomePage && x.VisibleIndividually)
.OrderBy(x => x.DisplayOrder).ThenBy(x => x.Name).Select(x => x.Id);
- return await Task.FromResult(query.ToList());
+ return await _productRepository.ToListAsync(query);
}
/// <summary>
@@ -78,7 +78,7 @@ public class ProductService : IProductService
.OrderBy(x => x.DisplayOrder).ThenBy(x => x.Name)
.Select(x => x.Id);
- var products = await Task.FromResult(query.ToList());
+ var products = await _productRepository.ToListAsync(query);
return products;
}
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/ProductTagService.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductTagService.cs
index a06fa9cda..de83876e7 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/ProductTagService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/ProductTagService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Data;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Caching;
@@ -74,7 +74,7 @@ public class ProductTagService : IProductTagService
public virtual async Task<IList<ProductTag>> GetAllProductTags()
{
return await _cacheBase.GetAsync(CacheKey.PRODUCTTAG_ALL_KEY,
- async () => await Task.FromResult(_productTagRepository.Table.ToList()));
+ async () => await _productTagRepository.ToListAsync(_productTagRepository.Table));
}
/// <summary>
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/RecentlyViewedProductsService.cs b/src/Business/Grand.Business.Catalog/Services/Products/RecentlyViewedProductsService.cs
index 171e85f80..8b7f73b9a 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/RecentlyViewedProductsService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/RecentlyViewedProductsService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Data;
using Grand.Domain.Catalog;
using Grand.Infrastructure.Caching;
@@ -70,7 +70,7 @@ public class RecentlyViewedProductsService : IRecentlyViewedProductsService
where p.CustomerId == customerId
orderby p.CreatedOnUtc descending
select p.ProductId;
- return await Task.FromResult(query.Take(number).ToList());
+ return await _recentlyViewedProducts.ToListAsync(query.Take(number));
});
}
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/SpecificationAttributeService.cs b/src/Business/Grand.Business.Catalog/Services/Products/SpecificationAttributeService.cs
index cebaed7b8..86b414ebe 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/SpecificationAttributeService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/SpecificationAttributeService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Catalog.Products;
+using Grand.Business.Core.Interfaces.Catalog.Products;
using Grand.Data;
using Grand.Domain;
using Grand.Domain.Catalog;
@@ -72,8 +72,8 @@ public class SpecificationAttributeService : ISpecificationAttributeService
var key = string.Format(CacheKey.SPECIFICATION_BY_SENAME, sename);
return await _cacheBase.GetAsync(key, async () =>
- await Task.FromResult(_specificationAttributeRepository.Table
- .FirstOrDefault(x => x.SeName == sename)));
+ await _specificationAttributeRepository.FirstOrDefaultAsync(_specificationAttributeRepository.Table
+ .Where(x => x.SeName == sename)));
}
@@ -178,7 +178,7 @@ public class SpecificationAttributeService : ISpecificationAttributeService
var query = from p in _specificationAttributeRepository.Table
where p.SpecificationAttributeOptions.Any(x => x.Id == specificationAttributeOptionId)
select p;
- return await Task.FromResult(query.FirstOrDefault());
+ return await _specificationAttributeRepository.FirstOrDefaultAsync(query);
});
}
diff --git a/src/Business/Grand.Business.Catalog/Services/Tax/TaxCategoryService.cs b/src/Business/Grand.Business.Catalog/Services/Tax/TaxCategoryService.cs
index bb526d847..0da4f9548 100644
--- a/src/Business/Grand.Business.Catalog/Services/Tax/TaxCategoryService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Tax/TaxCategoryService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Catalog.Tax;
+using Grand.Business.Core.Interfaces.Catalog.Tax;
using Grand.Data;
using Grand.Domain.Tax;
using Grand.Infrastructure.Caching;
@@ -55,7 +55,7 @@ public class TaxCategoryService : ITaxCategoryService
var query = _taxCategoryRepository.Table.AsQueryable();
if (!string.IsNullOrEmpty(storeId))
query = query.Where(tc => tc.StoreId == storeId || string.IsNullOrEmpty(tc.StoreId));
- return await Task.FromResult(query.OrderBy(tc => tc.DisplayOrder).ToList());
+ return await _taxCategoryRepository.ToListAsync(query.OrderBy(tc => tc.DisplayOrder));
});
}
diff --git a/src/Business/Grand.Business.Checkout/Queries/Handlers/Orders/GetMerchandiseReturnCountQueryHandler.cs b/src/Business/Grand.Business.Checkout/Queries/Handlers/Orders/GetMerchandiseReturnCountQueryHandler.cs
index ba56c53b3..fb4f0536a 100644
--- a/src/Business/Grand.Business.Checkout/Queries/Handlers/Orders/GetMerchandiseReturnCountQueryHandler.cs
+++ b/src/Business/Grand.Business.Checkout/Queries/Handlers/Orders/GetMerchandiseReturnCountQueryHandler.cs
@@ -16,9 +16,9 @@ public class GetMerchandiseReturnCountQueryHandler : IRequestHandler<GetMerchand
public async Task<int> Handle(GetMerchandiseReturnCountQuery request, CancellationToken cancellationToken)
{
- return await Task.FromResult(
- _merchandiseReturnRepository.Table.Count(x => x.MerchandiseReturnStatusId == request.RequestStatusId &&
- (string.IsNullOrEmpty(request.StoreId) ||
- x.StoreId == request.StoreId)));
+ return await _merchandiseReturnRepository.CountAsync(
+ _merchandiseReturnRepository.Table.Where(x => x.MerchandiseReturnStatusId == request.RequestStatusId &&
+ (string.IsNullOrEmpty(request.StoreId) ||
+ x.StoreId == request.StoreId)), cancellationToken);
}
}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeService.cs b/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeService.cs
index 8bc0f11af..6bc68c585 100644
--- a/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Checkout.CheckoutAttributes;
+using Grand.Business.Core.Interfaces.Checkout.CheckoutAttributes;
using Grand.Data;
using Grand.Domain.Customers;
using Grand.Domain.Orders;
@@ -85,7 +85,7 @@ public class CheckoutAttributeService : ICheckoutAttributeService
}
if (excludeShippableAttributes) query = query.Where(x => !x.ShippableProductRequired);
- return await Task.FromResult(query.ToList());
+ return await _checkoutAttributeRepository.ToListAsync(query);
});
}
diff --git a/src/Business/Grand.Business.Checkout/Services/GiftVouchers/GiftVoucherService.cs b/src/Business/Grand.Business.Checkout/Services/GiftVouchers/GiftVoucherService.cs
index 7951491ce..91ca9730c 100644
--- a/src/Business/Grand.Business.Checkout/Services/GiftVouchers/GiftVoucherService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/GiftVouchers/GiftVoucherService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Checkout.GiftVouchers;
+using Grand.Business.Core.Interfaces.Checkout.GiftVouchers;
using Grand.Business.Core.Queries.Checkout.Orders;
using Grand.Data;
using Grand.Domain;
@@ -89,7 +89,7 @@ public class GiftVoucherService : IGiftVoucherService
select h;
query = query.Where(x => x.UsedWithOrderId == orderId);
- return await Task.FromResult(query.ToList());
+ return await _giftVoucherRepository.ToListAsync(query);
}
/// <summary>
@@ -156,7 +156,7 @@ public class GiftVoucherService : IGiftVoucherService
gc.PurchasedWithOrderItem != null && gc.PurchasedWithOrderItem.Id == purchasedWithOrderItemId);
query = query.OrderBy(gc => gc.Id);
- return await Task.FromResult(query.ToList());
+ return await _giftVoucherRepository.ToListAsync(query);
}
/// <summary>
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/LoyaltyPointsService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/LoyaltyPointsService.cs
index 11d3e48ec..214341d57 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/LoyaltyPointsService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/LoyaltyPointsService.cs
@@ -58,7 +58,7 @@ public class LoyaltyPointsService : ILoyaltyPointsService
//Id as tie-breaker - entries created within the same millisecond share CreatedOnUtc
query = query.OrderByDescending(rph => rph.CreatedOnUtc).ThenByDescending(rph => rph.Id);
- var lastRph = await Task.FromResult(query.FirstOrDefault());
+ var lastRph = await _rphRepository.FirstOrDefaultAsync(query);
return lastRph?.PointsBalance ?? 0;
}
@@ -107,7 +107,7 @@ public class LoyaltyPointsService : ILoyaltyPointsService
query = query.Where(rph => rph.StoreId == storeId);
query = query.OrderByDescending(rph => rph.CreatedOnUtc).ThenByDescending(rph => rph.Id);
- return await Task.FromResult(query.ToList());
+ return await _rphRepository.ToListAsync(query);
}
#endregion
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/MerchandiseReturnService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/MerchandiseReturnService.cs
index 22e95ddcf..73e8c6027 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/MerchandiseReturnService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/MerchandiseReturnService.cs
@@ -73,9 +73,10 @@ public class MerchandiseReturnService : IMerchandiseReturnService
/// </summary>
/// <param name="id">Merchandise return identifier</param>
/// <returns>Merchandise return</returns>
- public virtual Task<MerchandiseReturn> GetMerchandiseReturnById(int id)
+ public virtual async Task<MerchandiseReturn> GetMerchandiseReturnById(int id)
{
- return Task.FromResult(_merchandiseReturnRepository.Table.FirstOrDefault(x => x.ReturnNumber == id));
+ return await _merchandiseReturnRepository.FirstOrDefaultAsync(
+ _merchandiseReturnRepository.Table.Where(x => x.ReturnNumber == id));
}
/// <summary>
@@ -368,7 +369,7 @@ public class MerchandiseReturnService : IMerchandiseReturnService
orderby merchandiseReturnNote.CreatedOnUtc descending
select merchandiseReturnNote;
- return await Task.FromResult(query.ToList());
+ return await _merchandiseReturnNoteRepository.ToListAsync(query);
}
/// <summary>
@@ -376,10 +377,10 @@ public class MerchandiseReturnService : IMerchandiseReturnService
/// </summary>
/// <param name="merchandiseReturnNoteId">The merchandise return note identifier</param>
/// <returns>MerchandiseReturnNote</returns>
- public virtual Task<MerchandiseReturnNote> GetMerchandiseReturnNote(string merchandiseReturnNoteId)
+ public virtual async Task<MerchandiseReturnNote> GetMerchandiseReturnNote(string merchandiseReturnNoteId)
{
- return Task.FromResult(
- _merchandiseReturnNoteRepository.Table.FirstOrDefault(x => x.Id == merchandiseReturnNoteId));
+ return await _merchandiseReturnNoteRepository.FirstOrDefaultAsync(
+ _merchandiseReturnNoteRepository.Table.Where(x => x.Id == merchandiseReturnNoteId));
}
#endregion
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/OrderService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/OrderService.cs
index 068f65c03..f427fccb9 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/OrderService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/OrderService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Commands.Checkout.Orders;
+using Grand.Business.Core.Commands.Checkout.Orders;
using Grand.Business.Core.Interfaces.Checkout.Orders;
using Grand.Business.Core.Queries.Checkout.Orders;
using Grand.Data;
@@ -64,13 +64,13 @@ public class OrderService : IOrderService
/// </summary>
/// <param name="orderItemId">The order item identifier</param>
/// <returns>Order</returns>
- public virtual Task<Order> GetOrderByOrderItemId(string orderItemId)
+ public virtual async Task<Order> GetOrderByOrderItemId(string orderItemId)
{
var query = from o in _orderRepository.Table
where o.OrderItems.Any(x => x.Id == orderItemId)
select o;
- return Task.FromResult(query.FirstOrDefault());
+ return await _orderRepository.FirstOrDefaultAsync(query);
}
/// <summary>
@@ -78,9 +78,10 @@ public class OrderService : IOrderService
/// </summary>
/// <param name="orderNumber">The order number</param>
/// <returns>Order</returns>
- public virtual Task<Order> GetOrderByNumber(int orderNumber)
+ public virtual async Task<Order> GetOrderByNumber(int orderNumber)
{
- return Task.FromResult(_orderRepository.Table.FirstOrDefault(x => x.OrderNumber == orderNumber));
+ return await _orderRepository.FirstOrDefaultAsync(
+ _orderRepository.Table.Where(x => x.OrderNumber == orderNumber));
}
/// <summary>
@@ -93,7 +94,8 @@ public class OrderService : IOrderService
if (string.IsNullOrEmpty(code))
return new List<Order>();
- return await Task.FromResult(_orderRepository.Table.Where(x => x.Code == code.ToUpperInvariant()).ToList());
+ return await _orderRepository.ToListAsync(
+ _orderRepository.Table.Where(x => x.Code == code.ToUpperInvariant()));
}
@@ -110,7 +112,7 @@ public class OrderService : IOrderService
var query = from o in _orderRepository.Table
where orderIds.Contains(o.Id)
select o;
- var orders = await Task.FromResult(query.ToList());
+ var orders = await _orderRepository.ToListAsync(query);
//sort by passed identifiers
return orderIds.Select(id => orders.FirstOrDefault(order => order.Id == id))
.Where(order => order != null)
@@ -122,12 +124,12 @@ public class OrderService : IOrderService
/// </summary>
/// <param name="orderGuid">The order identifier</param>
/// <returns>Order</returns>
- public virtual Task<Order> GetOrderByGuid(Guid orderGuid)
+ public virtual async Task<Order> GetOrderByGuid(Guid orderGuid)
{
var query = from o in _orderRepository.Table
where o.OrderGuid == orderGuid
select o;
- return Task.FromResult(query.FirstOrDefault());
+ return await _orderRepository.FirstOrDefaultAsync(query);
}
/// <summary>
@@ -258,7 +260,7 @@ public class OrderService : IOrderService
/// </summary>
/// <param name="orderItemGuid">Order identifier</param>
/// <returns>Order item</returns>
- public virtual Task<OrderItem> GetOrderItemByGuid(Guid orderItemGuid)
+ public virtual async Task<OrderItem> GetOrderItemByGuid(Guid orderItemGuid)
{
var query = from order in _orderRepository.Table
from orderItem in order.OrderItems
@@ -268,7 +270,7 @@ public class OrderService : IOrderService
where orderItem.OrderItemGuid == orderItemGuid
select orderItem;
- return Task.FromResult(query.FirstOrDefault());
+ return await _orderRepository.FirstOrDefaultAsync(query);
}
#endregion
@@ -310,7 +312,7 @@ public class OrderService : IOrderService
orderby orderNote.CreatedOnUtc descending
select orderNote;
- return await Task.FromResult(query.ToList());
+ return await _orderNoteRepository.ToListAsync(query);
}
/// <summary>
@@ -318,9 +320,10 @@ public class OrderService : IOrderService
/// </summary>
/// <param name="orderNoteId">Order note identifier</param>
/// <returns>OrderNote</returns>
- public virtual Task<OrderNote> GetOrderNote(string orderNoteId)
+ public virtual async Task<OrderNote> GetOrderNote(string orderNoteId)
{
- return Task.FromResult(_orderNoteRepository.Table.FirstOrDefault(x => x.Id == orderNoteId));
+ return await _orderNoteRepository.FirstOrDefaultAsync(
+ _orderNoteRepository.Table.Where(x => x.Id == orderNoteId));
}
#endregion
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/OrderStatusService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/OrderStatusService.cs
index 8dcc49ffa..bd80c2d85 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/OrderStatusService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/OrderStatusService.cs
@@ -32,7 +32,7 @@ public class OrderStatusService : IOrderStatusService
select p;
query = query.OrderBy(l => l.DisplayOrder);
- return await Task.FromResult(query.ToList());
+ return await _orderStatusRepository.ToListAsync(query);
});
return orderStatuses;
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/OrderTagService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/OrderTagService.cs
index b854cfab7..ea82541c1 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/OrderTagService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/OrderTagService.cs
@@ -65,7 +65,7 @@ public class OrderTagService : IOrderTagService
/// <returns>Order tags</returns>
public virtual async Task<IList<OrderTag>> GetAllOrderTags()
{
- return await Task.FromResult(_orderTagRepository.Table.ToList());
+ return await _orderTagRepository.ToListAsync(_orderTagRepository.Table);
}
/// <summary>
diff --git a/src/Business/Grand.Business.Checkout/Services/Payments/PaymentTransactionService.cs b/src/Business/Grand.Business.Checkout/Services/Payments/PaymentTransactionService.cs
index 29f150a66..839b3a985 100644
--- a/src/Business/Grand.Business.Checkout/Services/Payments/PaymentTransactionService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Payments/PaymentTransactionService.cs
@@ -80,9 +80,8 @@ public class PaymentTransactionService : IPaymentTransactionService
/// <returns>PaymentTransaction</returns>
public virtual async Task<IList<PaymentTransaction>> GetByOrderCode(string orderCode)
{
- return await Task.FromResult(
- _repositoryPaymentTransaction.Table.Where(x => x.OrderCode == orderCode)
- .ToList());
+ return await _repositoryPaymentTransaction.ToListAsync(
+ _repositoryPaymentTransaction.Table.Where(x => x.OrderCode == orderCode));
}
/// <summary>
@@ -92,7 +91,8 @@ public class PaymentTransactionService : IPaymentTransactionService
/// <returns>PaymentTransaction</returns>
public virtual async Task<PaymentTransaction> GetOrderByGuid(Guid orderGuid)
{
- return await Task.FromResult(_repositoryPaymentTransaction.Table.FirstOrDefault(x => x.OrderGuid == orderGuid));
+ return await _repositoryPaymentTransaction.FirstOrDefaultAsync(
+ _repositoryPaymentTransaction.Table.Where(x => x.OrderGuid == orderGuid));
}
/// <summary>
@@ -113,7 +113,7 @@ public class PaymentTransactionService : IPaymentTransactionService
if (!string.IsNullOrEmpty(paymentMethodSystemName))
query = query.Where(c => c.PaymentMethodSystemName == paymentMethodSystemName);
- return await Task.FromResult(query.ToList());
+ return await _repositoryPaymentTransaction.ToListAsync(query);
}
/// <summary>
diff --git a/src/Business/Grand.Business.Checkout/Services/Shipping/ShipmentService.cs b/src/Business/Grand.Business.Checkout/Services/Shipping/ShipmentService.cs
index 31d994e22..33350d6ba 100644
--- a/src/Business/Grand.Business.Checkout/Services/Shipping/ShipmentService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Shipping/ShipmentService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
using Grand.Data;
using Grand.Domain;
using Grand.Domain.Shipping;
@@ -102,13 +102,14 @@ public class ShipmentService : IShipmentService
var query = from o in _shipmentRepository.Table
where shipmentIds.Contains(o.Id)
select o;
- return await Task.FromResult(query.ToList());
+ return await _shipmentRepository.ToListAsync(query);
}
public virtual async Task<IList<Shipment>> GetShipmentsByOrder(string orderId)
{
- return await Task.FromResult(_shipmentRepository.Table.Where(x => x.OrderId == orderId).ToList());
+ return await _shipmentRepository.ToListAsync(
+ _shipmentRepository.Table.Where(x => x.OrderId == orderId));
}
/// <summary>
@@ -201,7 +202,7 @@ public class ShipmentService : IShipmentService
orderby shipmentNote.CreatedOnUtc descending
select shipmentNote;
- return await Task.FromResult(query.ToList());
+ return await _shipmentNoteRepository.ToListAsync(query);
}
/// <summary>
@@ -209,9 +210,10 @@ public class ShipmentService : IShipmentService
/// </summary>
/// <param name="shipmentNoteId">Shipment note identifier</param>
/// <returns>shipmentNote</returns>
- public virtual Task<ShipmentNote> GetShipmentNote(string shipmentNoteId)
+ public virtual async Task<ShipmentNote> GetShipmentNote(string shipmentNoteId)
{
- return Task.FromResult(_shipmentNoteRepository.Table.FirstOrDefault(x => x.Id == shipmentNoteId));
+ return await _shipmentNoteRepository.FirstOrDefaultAsync(
+ _shipmentNoteRepository.Table.Where(x => x.Id == shipmentNoteId));
}
#endregion
diff --git a/src/Business/Grand.Business.Checkout/Services/Shipping/ShippingMethodService.cs b/src/Business/Grand.Business.Checkout/Services/Shipping/ShippingMethodService.cs
index 59eae7116..cb96b3861 100644
--- a/src/Business/Grand.Business.Checkout/Services/Shipping/ShippingMethodService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Shipping/ShippingMethodService.cs
@@ -84,7 +84,7 @@ public class ShippingMethodService : IShippingMethodService
query = query.OrderBy(sm => sm.DisplayOrder);
- var shippingMethods = await Task.FromResult(query.ToList());
+ var shippingMethods = await _shippingMethodRepository.ToListAsync(query);
if (!string.IsNullOrEmpty(filterByCountryId))
shippingMethods = shippingMethods.Where(x => !x.CountryRestrictionExists(filterByCountryId)).ToList();
diff --git a/src/Business/Grand.Business.Cms/Services/BlogService.cs b/src/Business/Grand.Business.Cms/Services/BlogService.cs
index 7fc75280a..de7f13a8e 100644
--- a/src/Business/Grand.Business.Cms/Services/BlogService.cs
+++ b/src/Business/Grand.Business.Cms/Services/BlogService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Cms;
+using Grand.Business.Core.Interfaces.Cms;
using Grand.Data;
using Grand.Domain;
using Grand.Domain.Blogs;
@@ -231,7 +231,7 @@ public class BlogService : IBlogService
where (customerId == "" || c.CustomerId == customerId) && (storeId == "" || c.StoreId == storeId)
select c;
- return await Task.FromResult(query.ToList());
+ return await _blogCommentRepository.ToListAsync(query);
}
/// <summary>
@@ -251,7 +251,7 @@ public class BlogService : IBlogService
orderby c.CreatedOnUtc
select c;
- return await Task.FromResult(query.ToList());
+ return await _blogCommentRepository.ToListAsync(query);
}
/// <summary>
@@ -316,8 +316,8 @@ public class BlogService : IBlogService
/// <returns></returns>
public virtual async Task<IList<BlogCategory>> GetBlogCategoryByPostId(string blogPostId)
{
- return await Task.FromResult(_blogCategoryRepository.Table
- .Where(x => x.BlogPosts.Any(x => x.BlogPostId == blogPostId)).ToList());
+ return await _blogCategoryRepository.ToListAsync(_blogCategoryRepository.Table
+ .Where(x => x.BlogPosts.Any(x => x.BlogPostId == blogPostId)));
}
/// <summary>
@@ -344,7 +344,7 @@ public class BlogService : IBlogService
if (!string.IsNullOrEmpty(storeId) && !_accessControlConfig.IgnoreStoreLimitations)
query = query.Where(b => b.Stores.Contains(storeId) || !b.LimitedToStores);
- return await Task.FromResult(query.OrderBy(x => x.DisplayOrder).ToList());
+ return await _blogCategoryRepository.ToListAsync(query.OrderBy(x => x.DisplayOrder));
}
/// <summary>
@@ -463,7 +463,7 @@ public class BlogService : IBlogService
orderby bp.DisplayOrder
select bp;
- return await Task.FromResult(query.ToList());
+ return await _blogProductRepository.ToListAsync(query);
}
#endregion
diff --git a/src/Business/Grand.Business.Cms/Services/KnowledgebaseService.cs b/src/Business/Grand.Business.Cms/Services/KnowledgebaseService.cs
index be239f5ca..97da98dab 100644
--- a/src/Business/Grand.Business.Cms/Services/KnowledgebaseService.cs
+++ b/src/Business/Grand.Business.Cms/Services/KnowledgebaseService.cs
@@ -138,7 +138,7 @@ public class KnowledgebaseService : IKnowledgebaseService
query = query.Where(x => x.Published);
query = query.Where(x => x.Id == id);
query = ApplyStandardFilter(query);
- var toReturn = await Task.FromResult(query.FirstOrDefault());
+ var toReturn = await _knowledgebaseCategoryRepository.FirstOrDefaultAsync(query);
return toReturn;
});
}
@@ -189,7 +189,7 @@ public class KnowledgebaseService : IKnowledgebaseService
select p;
query = ApplyStandardFilter(query);
query = query.OrderBy(x => x.DisplayOrder);
- return await Task.FromResult(query.ToList());
+ return (await _knowledgebaseArticleRepository.ToListAsync(query)).ToList();
}
/// <summary>
@@ -237,8 +237,9 @@ public class KnowledgebaseService : IKnowledgebaseService
public virtual async Task<IPagedList<KnowledgebaseArticle>> GetKnowledgebaseArticlesByCategoryId(string id,
int pageIndex = 0, int pageSize = int.MaxValue)
{
- var articles = await Task.FromResult(_knowledgebaseArticleRepository.Table.Where(x => x.ParentCategoryId == id)
- .OrderBy(x => x.DisplayOrder).ToList());
+ var articles = await _knowledgebaseArticleRepository.ToListAsync(
+ _knowledgebaseArticleRepository.Table.Where(x => x.ParentCategoryId == id)
+ .OrderBy(x => x.DisplayOrder));
return new PagedList<KnowledgebaseArticle>(articles, pageIndex, pageSize);
}
@@ -259,7 +260,7 @@ public class KnowledgebaseService : IKnowledgebaseService
query = ApplyStandardFilter(query);
query = query.OrderBy(x => x.DisplayOrder);
- return await Task.FromResult(query.ToList());
+ return (await _knowledgebaseCategoryRepository.ToListAsync(query)).ToList();
});
}
@@ -280,7 +281,7 @@ public class KnowledgebaseService : IKnowledgebaseService
query = ApplyStandardFilter(query);
query = query.OrderBy(x => x.DisplayOrder);
- return await Task.FromResult(query.ToList());
+ return (await _knowledgebaseArticleRepository.ToListAsync(query)).ToList();
});
}
@@ -300,7 +301,7 @@ public class KnowledgebaseService : IKnowledgebaseService
query = query.Where(x => x.Published);
query = query.Where(x => x.Id == id);
query = ApplyStandardFilter(query);
- return await Task.FromResult(query.FirstOrDefault());
+ return await _knowledgebaseArticleRepository.FirstOrDefaultAsync(query);
});
}
@@ -322,7 +323,7 @@ public class KnowledgebaseService : IKnowledgebaseService
query = ApplyStandardFilter(query);
query = query.OrderBy(x => x.DisplayOrder);
- return await Task.FromResult(query.ToList());
+ return (await _knowledgebaseArticleRepository.ToListAsync(query)).ToList();
});
}
@@ -347,7 +348,7 @@ public class KnowledgebaseService : IKnowledgebaseService
query = ApplyStandardFilter(query);
query = query.OrderBy(x => x.DisplayOrder);
- return await Task.FromResult(query.ToList());
+ return (await _knowledgebaseArticleRepository.ToListAsync(query)).ToList();
});
}
@@ -372,7 +373,7 @@ public class KnowledgebaseService : IKnowledgebaseService
query = ApplyStandardFilter(query);
query = query.OrderBy(x => x.DisplayOrder);
- return await Task.FromResult(query.ToList());
+ return (await _knowledgebaseCategoryRepository.ToListAsync(query)).ToList();
});
}
@@ -393,7 +394,7 @@ public class KnowledgebaseService : IKnowledgebaseService
query = query.Where(x => x.ShowOnHomepage);
query = ApplyStandardFilter(query);
query = query.OrderBy(x => x.DisplayOrder);
- return await Task.FromResult(query.ToList());
+ return (await _knowledgebaseArticleRepository.ToListAsync(query)).ToList();
});
}
@@ -418,7 +419,7 @@ public class KnowledgebaseService : IKnowledgebaseService
|| p.Name.ToLower().Contains(name.ToLower()));
query = query.OrderBy(x => x.DisplayOrder);
- var toReturn = await Task.FromResult(query.ToList());
+ var toReturn = await _knowledgebaseArticleRepository.ToListAsync(query);
return new PagedList<KnowledgebaseArticle>(toReturn, pageIndex, pageSize);
}
@@ -462,7 +463,7 @@ public class KnowledgebaseService : IKnowledgebaseService
where c.ArticleId == articleId
orderby c.CreatedOnUtc
select c;
- return await Task.FromResult(query.ToList());
+ return await _articleCommentRepository.ToListAsync(query);
}
public virtual async Task DeleteArticleComment(KnowledgebaseArticleComment articleComment)
@@ -483,7 +484,7 @@ public class KnowledgebaseService : IKnowledgebaseService
orderby c.CreatedOnUtc
where customerId == "" || c.CustomerId == customerId
select c;
- return await Task.FromResult(query.ToList());
+ return await _articleCommentRepository.ToListAsync(query);
}
/// <summary>
diff --git a/src/Business/Grand.Business.Cms/Services/NewsService.cs b/src/Business/Grand.Business.Cms/Services/NewsService.cs
index 05e3868f1..09ab397bd 100644
--- a/src/Business/Grand.Business.Cms/Services/NewsService.cs
+++ b/src/Business/Grand.Business.Cms/Services/NewsService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Cms;
+using Grand.Business.Core.Interfaces.Cms;
using Grand.Data;
using Grand.Domain;
using Grand.Domain.Customers;
@@ -158,7 +158,7 @@ public class NewsService : INewsService
where customerId == "" || c.CustomerId == customerId
select c;
- return await Task.FromResult(query2.ToList());
+ return await _newsItemRepository.ToListAsync(query2);
}
#endregion
diff --git a/src/Business/Grand.Business.Cms/Services/PageLayoutService.cs b/src/Business/Grand.Business.Cms/Services/PageLayoutService.cs
index 7692742c0..a3dbfcb88 100644
--- a/src/Business/Grand.Business.Cms/Services/PageLayoutService.cs
+++ b/src/Business/Grand.Business.Cms/Services/PageLayoutService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Cms;
+using Grand.Business.Core.Interfaces.Cms;
using Grand.Data;
using Grand.Domain.Pages;
using Grand.Infrastructure.Caching;
@@ -54,7 +54,7 @@ public class PageLayoutService : IPageLayoutService
orderby pt.DisplayOrder
select pt;
- return await Task.FromResult(query.ToList());
+ return await _pageLayoutRepository.ToListAsync(query);
});
}
diff --git a/src/Business/Grand.Business.Common/Services/Addresses/AddressAttributeService.cs b/src/Business/Grand.Business.Common/Services/Addresses/AddressAttributeService.cs
index aa84feb8f..f070246ad 100644
--- a/src/Business/Grand.Business.Common/Services/Addresses/AddressAttributeService.cs
+++ b/src/Business/Grand.Business.Common/Services/Addresses/AddressAttributeService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Common.Addresses;
+using Grand.Business.Core.Interfaces.Common.Addresses;
using Grand.Data;
using Grand.Domain.Common;
using Grand.Infrastructure.Caching;
@@ -79,7 +79,7 @@ public class AddressAttributeService : IAddressAttributeService
where !aa.LimitedToStores || aa.Stores.Contains(storeId)
select aa;
- return await Task.FromResult(query.ToList());
+ return await _addressAttributeRepository.ToListAsync(query);
});
}
diff --git a/src/Business/Grand.Business.Common/Services/Directory/CountryService.cs b/src/Business/Grand.Business.Common/Services/Directory/CountryService.cs
index e1ff3b1a0..def938acb 100644
--- a/src/Business/Grand.Business.Common/Services/Directory/CountryService.cs
+++ b/src/Business/Grand.Business.Common/Services/Directory/CountryService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Extensions;
+using Grand.Business.Core.Extensions;
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Data;
using Grand.Domain.Directory;
@@ -75,7 +75,7 @@ public class CountryService : ICountryService
where !p.LimitedToStores || p.Stores.Contains(storeId)
select p;
- var countries = await Task.FromResult(query.OrderBy(x => x.DisplayOrder).ThenBy(x => x.Name).ToList());
+ var countries = await _countryRepository.ToListAsync(query.OrderBy(x => x.DisplayOrder).ThenBy(x => x.Name));
if (!string.IsNullOrEmpty(languageId))
countries = countries
.OrderBy(c => c.DisplayOrder)
@@ -140,7 +140,7 @@ public class CountryService : ICountryService
var query = from c in _countryRepository.Table
where countryIds.Contains(c.Id)
select c;
- var countries = await Task.FromResult(query.ToList());
+ var countries = await _countryRepository.ToListAsync(query);
//sort by passed identifiers
return countryIds.Select(id => countries.FirstOrDefault(country => country.Id == id))
.Where(country => country != null)
diff --git a/src/Business/Grand.Business.Common/Services/Directory/CurrencyService.cs b/src/Business/Grand.Business.Common/Services/Directory/CurrencyService.cs
index 2a7c0fc4f..5f37c1c08 100644
--- a/src/Business/Grand.Business.Common/Services/Directory/CurrencyService.cs
+++ b/src/Business/Grand.Business.Common/Services/Directory/CurrencyService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Security;
using Grand.Data;
using Grand.Domain.Directory;
@@ -99,7 +99,7 @@ public class CurrencyService : ICurrencyService
var query = from q in _currencyRepository.Table
where q.CurrencyCode.ToLowerInvariant() == currencyCode.ToLowerInvariant()
select q;
- return await Task.FromResult(query.FirstOrDefault());
+ return await _currencyRepository.FirstOrDefaultAsync(query);
});
}
@@ -120,7 +120,7 @@ public class CurrencyService : ICurrencyService
if (!showHidden)
query = query.Where(c => c.Published);
query = query.OrderBy(c => c.DisplayOrder);
- return await Task.FromResult(query.ToList());
+ return await _currencyRepository.ToListAsync(query);
});
//store acl
diff --git a/src/Business/Grand.Business.Common/Services/Directory/GroupService.cs b/src/Business/Grand.Business.Common/Services/Directory/GroupService.cs
index d95393ca8..0c7f5b8e2 100644
--- a/src/Business/Grand.Business.Common/Services/Directory/GroupService.cs
+++ b/src/Business/Grand.Business.Common/Services/Directory/GroupService.cs
@@ -49,8 +49,8 @@ public class GroupService : IGroupService
var key = string.Format(CacheKey.CUSTOMERGROUPS_BY_SYSTEMNAME_KEY, systemName);
return await _cacheBase.GetAsync(key, async () =>
{
- return await Task.FromResult(
- _customerGroupRepository.Table.FirstOrDefault(x => x.SystemName == systemName));
+ return await _customerGroupRepository.FirstOrDefaultAsync(
+ _customerGroupRepository.Table.Where(x => x.SystemName == systemName));
});
}
@@ -202,7 +202,7 @@ public class GroupService : IGroupService
var query = from cr in _customerGroupRepository.Table
orderby cr.Name
select cr;
- return await Task.FromResult(query.ToList());
+ return await _customerGroupRepository.ToListAsync(query);
});
return customerGroups.Where(x => ids.Contains(x.Id)).ToList();
}
diff --git a/src/Business/Grand.Business.Common/Services/Directory/HistoryService.cs b/src/Business/Grand.Business.Common/Services/Directory/HistoryService.cs
index 889269384..30db6b0dc 100644
--- a/src/Business/Grand.Business.Common/Services/Directory/HistoryService.cs
+++ b/src/Business/Grand.Business.Common/Services/Directory/HistoryService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Data;
using Grand.Domain;
using Grand.Domain.History;
@@ -30,8 +30,8 @@ public class HistoryService : IHistoryService
{
ArgumentNullException.ThrowIfNull(entity);
- var history = await Task.FromResult(_historyRepository.Table.Where(x => x.Object.Id == entity.Id)
- .Select(x => (T)x.Object).ToList());
+ var history = await _historyRepository.ToListAsync(_historyRepository.Table
+ .Where(x => x.Object.Id == entity.Id).Select(x => (T)x.Object));
return history;
}
@@ -39,7 +39,8 @@ public class HistoryService : IHistoryService
{
ArgumentNullException.ThrowIfNull(entity);
- var history = await Task.FromResult(_historyRepository.Table.Where(x => x.Object.Id == entity.Id).ToList());
+ var history = await _historyRepository.ToListAsync(
+ _historyRepository.Table.Where(x => x.Object.Id == entity.Id));
return history;
}
}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Common/Services/Localization/LanguageService.cs b/src/Business/Grand.Business.Common/Services/Localization/LanguageService.cs
index a2cb520a0..d449ab53a 100644
--- a/src/Business/Grand.Business.Common/Services/Localization/LanguageService.cs
+++ b/src/Business/Grand.Business.Common/Services/Localization/LanguageService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Data;
using Grand.Domain.Localization;
using Grand.Infrastructure.Caching;
@@ -59,7 +59,7 @@ public class LanguageService : ILanguageService
if (!showHidden)
query = query.Where(l => l.Published);
query = query.OrderBy(l => l.DisplayOrder);
- return await Task.FromResult(query.ToList());
+ return await _languageRepository.ToListAsync(query);
});
//store acl
@@ -96,7 +96,7 @@ public class LanguageService : ILanguageService
var query = from q in _languageRepository.Table
where q.UniqueSeoCode.ToLowerInvariant() == languageCode.ToLowerInvariant()
select q;
- return await Task.FromResult(query.FirstOrDefault());
+ return await _languageRepository.FirstOrDefaultAsync(query);
});
}
diff --git a/src/Business/Grand.Business.Common/Services/Localization/TranslationService.cs b/src/Business/Grand.Business.Common/Services/Localization/TranslationService.cs
index edab4d138..d72d03c8e 100644
--- a/src/Business/Grand.Business.Common/Services/Localization/TranslationService.cs
+++ b/src/Business/Grand.Business.Common/Services/Localization/TranslationService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Data;
using Grand.Domain.Localization;
using Grand.Infrastructure;
@@ -69,7 +69,7 @@ public class TranslationService : ITranslationService
orderby lsr.Name
where lsr.LanguageId == languageId && lsr.Name == name
select lsr;
- var translateResource = await Task.FromResult(query.FirstOrDefault());
+ var translateResource = await _translationRepository.FirstOrDefaultAsync(query);
return translateResource;
}
diff --git a/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs b/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs
index 4b3b3dff8..e19d1aa8f 100644
--- a/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs
+++ b/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Security;
using Grand.Data;
using Grand.Domain.Customers;
@@ -57,8 +57,8 @@ public class PermissionService : IPermissionService
return await _cacheBase.GetAsync(key, async () =>
{
var permissionRecord =
- await Task.FromResult(
- _permissionRepository.Table.FirstOrDefault(x => x.SystemName == permissionSystemName));
+ await _permissionRepository.FirstOrDefaultAsync(
+ _permissionRepository.Table.Where(x => x.SystemName == permissionSystemName));
return permissionRecord?.CustomerGroups.Contains(customerGroup.Id) ?? false;
});
}
@@ -114,7 +114,7 @@ public class PermissionService : IPermissionService
where pr.SystemName == systemName
select pr;
- return await Task.FromResult(query.FirstOrDefault());
+ return await _permissionRepository.FirstOrDefaultAsync(query);
}
/// <summary>
@@ -126,7 +126,7 @@ public class PermissionService : IPermissionService
var query = from pr in _permissionRepository.Table
orderby pr.Name
select pr;
- return await Task.FromResult(query.ToList());
+ return await _permissionRepository.ToListAsync(query);
}
/// <summary>
@@ -221,8 +221,8 @@ public class PermissionService : IPermissionService
/// <returns>Permission action</returns>
public virtual async Task<IList<PermissionAction>> GetPermissionActions(string systemName, string customerGroupId)
{
- return await Task.FromResult(_permissionActionRepository.Table
- .Where(x => x.SystemName == systemName && x.CustomerGroupId == customerGroupId).ToList());
+ return await _permissionActionRepository.ToListAsync(_permissionActionRepository.Table
+ .Where(x => x.SystemName == systemName && x.CustomerGroupId == customerGroupId));
}
/// <summary>
@@ -277,8 +277,8 @@ public class PermissionService : IPermissionService
permissionActionName);
var permissionAction = await _cacheBase.GetAsync(key, async () =>
{
- return await Task.FromResult(_permissionActionRepository.Table
- .FirstOrDefault(x =>
+ return await _permissionActionRepository.FirstOrDefaultAsync(_permissionActionRepository.Table
+ .Where(x =>
x.SystemName == permissionSystemName && x.CustomerGroupId == group.Id &&
x.Action == permissionActionName));
});
diff --git a/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs b/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs
index 7d0909c37..3938031ef 100644
--- a/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs
+++ b/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Common.Seo;
+using Grand.Business.Core.Interfaces.Common.Seo;
using Grand.Data;
using Grand.Domain;
using Grand.Domain.Seo;
@@ -104,7 +104,7 @@ public class SlugService : ISlugService
where ur.Slug == slug
orderby ur.IsActive
select ur;
- return await Task.FromResult(query.FirstOrDefault());
+ return await _urlEntityRepository.FirstOrDefaultAsync(query);
}
/// <summary>
@@ -170,7 +170,7 @@ public class SlugService : ISlugService
ur.LanguageId == languageId &&
ur.IsActive
select ur.Slug;
- var slug = await Task.FromResult(query.FirstOrDefault()) ?? "";
+ var slug = await _urlEntityRepository.FirstOrDefaultAsync(query) ?? "";
return slug;
});
}
diff --git a/src/Business/Grand.Business.Common/Services/Stores/StoreService.cs b/src/Business/Grand.Business.Common/Services/Stores/StoreService.cs
index 9585f22b8..4c412771c 100644
--- a/src/Business/Grand.Business.Common/Services/Stores/StoreService.cs
+++ b/src/Business/Grand.Business.Common/Services/Stores/StoreService.cs
@@ -1,4 +1,4 @@
-#nullable enable
+#nullable enable
using Grand.Business.Core.Interfaces.Common.Stores;
using Grand.Data;
@@ -52,7 +52,7 @@ public class StoreService : IStoreService
{
return await _cacheBase.GetAsync(CacheKey.STORES_ALL_KEY, async () =>
{
- return await Task.FromResult(_storeRepository.Table.OrderBy(x => x.DisplayOrder).ToList());
+ return await _storeRepository.ToListAsync(_storeRepository.Table.OrderBy(x => x.DisplayOrder));
});
}
diff --git a/src/Business/Grand.Business.Customers/Services/AffiliateService.cs b/src/Business/Grand.Business.Customers/Services/AffiliateService.cs
index 3ed7cc2c0..fc8845635 100644
--- a/src/Business/Grand.Business.Customers/Services/AffiliateService.cs
+++ b/src/Business/Grand.Business.Customers/Services/AffiliateService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Customers;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Data;
using Grand.Domain;
using Grand.Domain.Affiliates;
@@ -62,7 +62,7 @@ public class AffiliateService : IAffiliateService
var query = from a in _affiliateRepository.Table
where a.FriendlyUrlName != null && a.FriendlyUrlName.Contains(friendlyUrlName.ToLowerInvariant())
select a;
- var affiliate = await Task.FromResult(query.FirstOrDefault());
+ var affiliate = await _affiliateRepository.FirstOrDefaultAsync(query);
return affiliate;
}
diff --git a/src/Business/Grand.Business.Customers/Services/CustomerAttributeService.cs b/src/Business/Grand.Business.Customers/Services/CustomerAttributeService.cs
index e51e83740..7b62a4f2b 100644
--- a/src/Business/Grand.Business.Customers/Services/CustomerAttributeService.cs
+++ b/src/Business/Grand.Business.Customers/Services/CustomerAttributeService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Customers;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Data;
using Grand.Domain.Customers;
using Grand.Infrastructure.Caching;
@@ -79,7 +79,7 @@ public class CustomerAttributeService : ICustomerAttributeService
where !ca.LimitedToStores || ca.Stores.Contains(storeId)
select ca;
- return await Task.FromResult(query.ToList());
+ return await _customerAttributeRepository.ToListAsync(query);
});
}
diff --git a/src/Business/Grand.Business.Customers/Services/CustomerHistoryPasswordService.cs b/src/Business/Grand.Business.Customers/Services/CustomerHistoryPasswordService.cs
index 61f7cebd7..222ef7602 100644
--- a/src/Business/Grand.Business.Customers/Services/CustomerHistoryPasswordService.cs
+++ b/src/Business/Grand.Business.Customers/Services/CustomerHistoryPasswordService.cs
@@ -47,11 +47,11 @@ public class CustomerHistoryPasswordService : ICustomerHistoryPasswordService
/// <returns>List of customer passwords</returns>
public virtual async Task<IList<CustomerHistoryPassword>> GetPasswords(string customerId, int passwordsToReturn)
{
- return await Task.FromResult(_customerHistoryPasswordProductRepository
- .Table
- .Where(x => x.CustomerId == customerId)
- .OrderByDescending(password => password.CreatedOnUtc)
- .Take(passwordsToReturn)
- .ToList());
+ return await _customerHistoryPasswordProductRepository.ToListAsync(
+ _customerHistoryPasswordProductRepository
+ .Table
+ .Where(x => x.CustomerId == customerId)
+ .OrderByDescending(password => password.CreatedOnUtc)
+ .Take(passwordsToReturn));
}
}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Customers/Services/CustomerNoteService.cs b/src/Business/Grand.Business.Customers/Services/CustomerNoteService.cs
index f3d4edf75..78649179b 100644
--- a/src/Business/Grand.Business.Customers/Services/CustomerNoteService.cs
+++ b/src/Business/Grand.Business.Customers/Services/CustomerNoteService.cs
@@ -77,7 +77,7 @@ public class CustomerNoteService : ICustomerNoteService
query = query.OrderByDescending(x => x.CreatedOnUtc);
- return await Task.FromResult(query.ToList());
+ return await _customerNoteRepository.ToListAsync(query);
}
#endregion
diff --git a/src/Business/Grand.Business.Customers/Services/CustomerService.cs b/src/Business/Grand.Business.Customers/Services/CustomerService.cs
index 7f31bd499..143fe7820 100644
--- a/src/Business/Grand.Business.Customers/Services/CustomerService.cs
+++ b/src/Business/Grand.Business.Customers/Services/CustomerService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Customers;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Queries.Customers;
using Grand.Data;
using Grand.Domain;
@@ -176,7 +176,7 @@ public class CustomerService : ICustomerService
if (!string.IsNullOrEmpty(salesEmployeeId))
query = query.Where(c => c.SeId == salesEmployeeId);
- return await Task.FromResult(query.Count());
+ return await _customerRepository.CountAsync(query);
}
/// <summary>
diff --git a/src/Business/Grand.Business.Customers/Services/SalesEmployeeService.cs b/src/Business/Grand.Business.Customers/Services/SalesEmployeeService.cs
index 5acf1e824..9e2f92b1a 100644
--- a/src/Business/Grand.Business.Customers/Services/SalesEmployeeService.cs
+++ b/src/Business/Grand.Business.Customers/Services/SalesEmployeeService.cs
@@ -42,7 +42,7 @@ public class SalesEmployeeService : ISalesEmployeeService
var query = from se in _salesEmployeeRepository.Table
orderby se.DisplayOrder
select se;
- return await Task.FromResult(query.ToList());
+ return await _salesEmployeeRepository.ToListAsync(query);
});
}
diff --git a/src/Business/Grand.Business.Customers/Services/UserApiService.cs b/src/Business/Grand.Business.Customers/Services/UserApiService.cs
index 6e40a2fd0..ce6344e61 100644
--- a/src/Business/Grand.Business.Customers/Services/UserApiService.cs
+++ b/src/Business/Grand.Business.Customers/Services/UserApiService.cs
@@ -30,7 +30,8 @@ public class UserApiService : IUserApiService
/// <param name="email">email</param>
public virtual async Task<UserApi> GetUserByEmail(string email)
{
- return await Task.FromResult(_userRepository.Table.FirstOrDefault(x => x.Email == email.ToLowerInvariant()));
+ return await _userRepository.FirstOrDefaultAsync(
+ _userRepository.Table.Where(x => x.Email == email.ToLowerInvariant()));
}
/// <summary>
diff --git a/src/Business/Grand.Business.Customers/Services/VendorService.cs b/src/Business/Grand.Business.Customers/Services/VendorService.cs
index 4000ace73..58df43c93 100644
--- a/src/Business/Grand.Business.Customers/Services/VendorService.cs
+++ b/src/Business/Grand.Business.Customers/Services/VendorService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Customers;
+using Grand.Business.Core.Interfaces.Customers;
using Grand.Data;
using Grand.Domain;
using Grand.Domain.Catalog;
@@ -181,7 +181,7 @@ public class VendorService : IVendorService
var query = from c in _vendorRepository.Table
where c.AppliedDiscounts.Any(x => x == discountId)
select c;
- return await Task.FromResult(query.ToList());
+ return await _vendorRepository.ToListAsync(query);
}
#region Vendor reviews
@@ -342,7 +342,7 @@ public class VendorService : IVendorService
query = query.Where(p => p.Name.ToLower().Contains(keywords.ToLower()));
//vendor filtering
if (!string.IsNullOrEmpty(vendorId)) query = query.Where(x => x.Id == vendorId);
- return await Task.FromResult(query.ToList());
+ return await _vendorRepository.ToListAsync(query);
}
#endregion
diff --git a/src/Business/Grand.Business.Marketing/Services/Campaigns/CampaignService.cs b/src/Business/Grand.Business.Marketing/Services/Campaigns/CampaignService.cs
index 145b945c3..2ec54e947 100644
--- a/src/Business/Grand.Business.Marketing/Services/Campaigns/CampaignService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Campaigns/CampaignService.cs
@@ -99,7 +99,7 @@ public class CampaignService(
var query = from c in campaignRepository.Table
orderby c.CreatedOnUtc
select c;
- return await Task.FromResult(query.ToList());
+ return await campaignRepository.ToListAsync(query);
}
public virtual async Task<IPagedList<CampaignHistory>> GetCampaignHistory(Campaign campaign, int pageIndex = 0,
diff --git a/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeService.cs b/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeService.cs
index 390ea74f1..6e8ede082 100644
--- a/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Marketing.Contacts;
+using Grand.Business.Core.Interfaces.Marketing.Contacts;
using Grand.Data;
using Grand.Domain.Customers;
using Grand.Domain.Messages;
@@ -84,7 +84,8 @@ public class ContactAttributeService : IContactAttributeService
query = query.OrderBy(c => c.DisplayOrder);
if ((string.IsNullOrEmpty(storeId) || _accessControlConfig.IgnoreStoreLimitations) &&
- (ignoreAcl || _accessControlConfig.IgnoreAcl)) return await Task.FromResult(query.ToList());
+ (ignoreAcl || _accessControlConfig.IgnoreAcl))
+ return await _contactAttributeRepository.ToListAsync(query);
if (!ignoreAcl && !_accessControlConfig.IgnoreAcl)
{
var allowedCustomerGroupsIds = _contextAccessor.WorkContext.CurrentCustomer.GetCustomerGroupIds();
@@ -98,7 +99,7 @@ public class ContactAttributeService : IContactAttributeService
query = from p in query
where !p.LimitedToStores || p.Stores.Contains(storeId)
select p;
- return await Task.FromResult(query.ToList());
+ return await _contactAttributeRepository.ToListAsync(query);
});
}
diff --git a/src/Business/Grand.Business.Marketing/Services/Courses/CourseActionService.cs b/src/Business/Grand.Business.Marketing/Services/Courses/CourseActionService.cs
index 93799967c..5f6159f6a 100644
--- a/src/Business/Grand.Business.Marketing/Services/Courses/CourseActionService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Courses/CourseActionService.cs
@@ -28,14 +28,14 @@ public class CourseActionService : ICourseActionService
where a.CustomerId == customerId && a.LessonId == lessonId
select a;
- return await Task.FromResult(query.FirstOrDefault());
+ return await _courseActionRepository.FirstOrDefaultAsync(query);
}
public virtual async Task<bool> CustomerLessonCompleted(string customerId, string lessonId)
{
- var query = await Task.FromResult((from a in _courseActionRepository.Table
+ var query = await _courseActionRepository.FirstOrDefaultAsync(from a in _courseActionRepository.Table
where a.CustomerId == customerId && a.LessonId == lessonId
- select a).FirstOrDefault());
+ select a);
return query is { Finished: true };
}
diff --git a/src/Business/Grand.Business.Marketing/Services/Courses/CourseLessonService.cs b/src/Business/Grand.Business.Marketing/Services/Courses/CourseLessonService.cs
index 650d6dc85..77cde4aab 100644
--- a/src/Business/Grand.Business.Marketing/Services/Courses/CourseLessonService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Courses/CourseLessonService.cs
@@ -35,7 +35,7 @@ public class CourseLessonService : ICourseLessonService
where c.CourseId == courseId
select c;
- return await Task.FromResult(query.ToList());
+ return await _courseLessonRepository.ToListAsync(query);
}
public virtual Task<CourseLesson> GetById(string id)
diff --git a/src/Business/Grand.Business.Marketing/Services/Courses/CourseLevelService.cs b/src/Business/Grand.Business.Marketing/Services/Courses/CourseLevelService.cs
index 80416fa54..fb3e0f89f 100644
--- a/src/Business/Grand.Business.Marketing/Services/Courses/CourseLevelService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Courses/CourseLevelService.cs
@@ -33,7 +33,7 @@ public class CourseLevelService : ICourseLevelService
orderby l.DisplayOrder
select l;
- return await Task.FromResult(query.ToList());
+ return await _courseLevelRepository.ToListAsync(query);
}
public virtual Task<CourseLevel> GetById(string id)
diff --git a/src/Business/Grand.Business.Marketing/Services/Courses/CourseSubjectService.cs b/src/Business/Grand.Business.Marketing/Services/Courses/CourseSubjectService.cs
index e23238f35..0b1d585ce 100644
--- a/src/Business/Grand.Business.Marketing/Services/Courses/CourseSubjectService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Courses/CourseSubjectService.cs
@@ -36,7 +36,7 @@ public class CourseSubjectService : ICourseSubjectService
orderby c.DisplayOrder
select c;
- return await Task.FromResult(query.ToList());
+ return await _courseSubjectRepository.ToListAsync(query);
}
public virtual Task<CourseSubject> GetById(string id)
diff --git a/src/Business/Grand.Business.Marketing/Services/Customers/CustomerProductService.cs b/src/Business/Grand.Business.Marketing/Services/Customers/CustomerProductService.cs
index c2cedfdd0..9828a5272 100644
--- a/src/Business/Grand.Business.Marketing/Services/Customers/CustomerProductService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Customers/CustomerProductService.cs
@@ -55,8 +55,8 @@ public class CustomerProductService : ICustomerProductService
var key = string.Format(CacheKey.CUSTOMER_PRODUCT_PRICE_KEY_ID, customerId, productId);
var productPrice = await _cacheBase.GetAsync(key, async () =>
{
- var pp = await Task.FromResult(
- _customerProductPriceRepository.Table.FirstOrDefault(x =>
+ var pp = await _customerProductPriceRepository.FirstOrDefaultAsync(
+ _customerProductPriceRepository.Table.Where(x =>
x.CustomerId == customerId && x.ProductId == productId));
return pp == null ? (null, false) : (pp, true);
});
@@ -155,7 +155,7 @@ public class CustomerProductService : ICustomerProductService
where pp.CustomerId == customerId && pp.ProductId == productId
select pp;
- return await Task.FromResult(query.FirstOrDefault());
+ return await _customerProductRepository.FirstOrDefaultAsync(query);
}
/// <summary>
diff --git a/src/Business/Grand.Business.Marketing/Services/Customers/CustomerTagService.cs b/src/Business/Grand.Business.Marketing/Services/Customers/CustomerTagService.cs
index fd223925e..baf23280c 100644
--- a/src/Business/Grand.Business.Marketing/Services/Customers/CustomerTagService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Customers/CustomerTagService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.Marketing.Customers;
+using Grand.Business.Core.Interfaces.Marketing.Customers;
using Grand.Data;
using Grand.Domain;
using Grand.Domain.Customers;
@@ -72,7 +72,7 @@ public class CustomerTagService : ICustomerTagService
/// <returns>Customer tags</returns>
public virtual async Task<IList<CustomerTag>> GetAllCustomerTags()
{
- return await Task.FromResult(_customerTagRepository.Table.ToList());
+ return await _customerTagRepository.ToListAsync(_customerTagRepository.Table);
}
/// <summary>
@@ -96,7 +96,7 @@ public class CustomerTagService : ICustomerTagService
where pt.Name == name
select pt;
- return await Task.FromResult(query.FirstOrDefault());
+ return await _customerTagRepository.FirstOrDefaultAsync(query);
}
/// <summary>
@@ -109,7 +109,7 @@ public class CustomerTagService : ICustomerTagService
var query = from pt in _customerTagRepository.Table
where pt.Name.ToLower().Contains(name.ToLower())
select pt;
- return await Task.FromResult(query.ToList());
+ return await _customerTagRepository.ToListAsync(query);
}
/// <summary>
@@ -195,7 +195,7 @@ public class CustomerTagService : ICustomerTagService
where cr.CustomerTagId == customerTagId
orderby cr.DisplayOrder
select cr;
- return await Task.FromResult(query.ToList());
+ return await _customerTagProductRepository.ToListAsync(query);
});
}
@@ -211,7 +211,7 @@ public class CustomerTagService : ICustomerTagService
where cr.CustomerTagId == customerTagId && cr.ProductId == productId
orderby cr.DisplayOrder
select cr;
- return await Task.FromResult(query.FirstOrDefault());
+ return await _customerTagProductRepository.FirstOrDefaultAsync(query);
}
/// <summary>
diff --git a/src/Business/Grand.Business.Marketing/Services/Documents/DocumentTypeService.cs b/src/Business/Grand.Business.Marketing/Services/Documents/DocumentTypeService.cs
index e21244cb6..780416493 100644
--- a/src/Business/Grand.Business.Marketing/Services/Documents/DocumentTypeService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Documents/DocumentTypeService.cs
@@ -32,7 +32,7 @@ public class DocumentTypeService : IDocumentTypeService
var query = from t in _documentTypeRepository.Table
orderby t.DisplayOrder
select t;
- return await Task.FromResult(query.ToList());
+ return await _documentTypeRepository.ToListAsync(query);
}
public virtual Task<DocumentType> GetById(string id)
diff --git a/src/Business/Grand.Business.Marketing/Services/Newsletters/NewsletterCategoryService.cs b/src/Business/Grand.Business.Marketing/Services/Newsletters/NewsletterCategoryService.cs
index f104217cd..e2bf4d66e 100644
--- a/src/Business/Grand.Business.Marketing/Services/Newsletters/NewsletterCategoryService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Newsletters/NewsletterCategoryService.cs
@@ -85,7 +85,7 @@ public class NewsletterCategoryService : INewsletterCategoryService
/// <returns>NewsletterCategories</returns>
public virtual async Task<IList<NewsletterCategory>> GetAllNewsletterCategory()
{
- return await Task.FromResult(_newsletterCategoryRepository.Table.ToList());
+ return await _newsletterCategoryRepository.ToListAsync(_newsletterCategoryRepository.Table);
}
/// <summary>
@@ -98,7 +98,7 @@ public class NewsletterCategoryService : INewsletterCategoryService
where !p.LimitedToStores || p.Stores.Contains(storeId)
orderby p.DisplayOrder
select p;
- return await Task.FromResult(query.ToList());
+ return await _newsletterCategoryRepository.ToListAsync(query);
}
#endregion
diff --git a/src/Business/Grand.Business.Marketing/Services/PushNotifications/PushNotificationsService.cs b/src/Business/Grand.Business.Marketing/Services/PushNotifications/PushNotificationsService.cs
index dce379018..0e81c18a1 100644
--- a/src/Business/Grand.Business.Marketing/Services/PushNotifications/PushNotificationsService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/PushNotifications/PushNotificationsService.cs
@@ -63,7 +63,8 @@ public class PushNotificationsService : IPushNotificationsService
/// <param name="customerId"></param>
public virtual async Task<PushRegistration> GetPushReceiverByCustomerId(string customerId)
{
- return await Task.FromResult(_pushRegistrationRepository.Table.FirstOrDefault(x => x.CustomerId == customerId));
+ return await _pushRegistrationRepository.FirstOrDefaultAsync(
+ _pushRegistrationRepository.Table.Where(x => x.CustomerId == customerId));
}
/// <summary>
@@ -81,7 +82,8 @@ public class PushNotificationsService : IPushNotificationsService
/// </summary>
public virtual async Task<List<PushRegistration>> GetAllowedPushReceivers()
{
- return await Task.FromResult(_pushRegistrationRepository.Table.Where(x => x.Allowed).ToList());
+ return (await _pushRegistrationRepository.ToListAsync(
+ _pushRegistrationRepository.Table.Where(x => x.Allowed))).ToList();
}
/// <summary>
@@ -89,7 +91,8 @@ public class PushNotificationsService : IPushNotificationsService
/// </summary>
public virtual async Task<int> GetAllowedReceivers()
{
- return await Task.FromResult(_pushRegistrationRepository.Table.Count(x => x.Allowed));
+ return await _pushRegistrationRepository.CountAsync(
+ _pushRegistrationRepository.Table.Where(x => x.Allowed));
}
/// <summary>
@@ -97,7 +100,8 @@ public class PushNotificationsService : IPushNotificationsService
/// </summary>
public virtual async Task<int> GetDeniedReceivers()
{
- return await Task.FromResult(_pushRegistrationRepository.Table.Count(x => !x.Allowed));
+ return await _pushRegistrationRepository.CountAsync(
+ _pushRegistrationRepository.Table.Where(x => !x.Allowed));
}
/// <summary>
diff --git a/src/Business/Grand.Business.Messages/Queries/Handlers/GetBidsByProductIdQueryHandler.cs b/src/Business/Grand.Business.Messages/Queries/Handlers/GetBidsByProductIdQueryHandler.cs
index c0388e509..19b4b28fc 100644
--- a/src/Business/Grand.Business.Messages/Queries/Handlers/GetBidsByProductIdQueryHandler.cs
+++ b/src/Business/Grand.Business.Messages/Queries/Handlers/GetBidsByProductIdQueryHandler.cs
@@ -16,9 +16,8 @@ public class GetBidsByProductIdQueryHandler : IRequestHandler<GetBidsByProductId
public async Task<IList<Bid>> Handle(GetBidsByProductIdQuery request, CancellationToken cancellationToken)
{
- return await Task.FromResult(_bidRepository
+ return await _bidRepository.ToListAsync(_bidRepository
.Table.Where(x => x.ProductId == request.ProductId)
- .OrderByDescending(x => x.Date)
- .ToList());
+ .OrderByDescending(x => x.Date), cancellationToken);
}
}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Storage/Services/PictureService.cs b/src/Business/Grand.Business.Storage/Services/PictureService.cs
index 62d9a073f..c857f9714 100644
--- a/src/Business/Grand.Business.Storage/Services/PictureService.cs
+++ b/src/Business/Grand.Business.Storage/Services/PictureService.cs
@@ -457,7 +457,7 @@ public class PictureService : IPictureService
Style = p.Style,
ExtraField = p.ExtraField
});
- return await Task.FromResult(query.FirstOrDefault());
+ return await _pictureRepository.FirstOrDefaultAsync(query);
});
}
diff --git a/src/Core/Grand.Data/IRepository.cs b/src/Core/Grand.Data/IRepository.cs
index ccf97b0a4..5cc68c746 100644
--- a/src/Core/Grand.Data/IRepository.cs
+++ b/src/Core/Grand.Data/IRepository.cs
@@ -177,6 +177,23 @@ public interface IRepository<T> where T : BaseEntity
/// <param name="cancellationToken">Cancellation token</param>
Task<int> CountAsync<TResult>(IQueryable<TResult> query, CancellationToken cancellationToken = default);
+ /// <summary>
+ /// Executes the query and returns its first result, or the default value when nothing matches
+ /// </summary>
+ /// <typeparam name="TResult">Type of the query result - the entity itself or a projection</typeparam>
+ /// <param name="query">Query built on top of <see cref="Table" /> or <see cref="TableCollection{C}" /></param>
+ /// <param name="cancellationToken">Cancellation token</param>
+ Task<TResult> FirstOrDefaultAsync<TResult>(IQueryable<TResult> query,
+ CancellationToken cancellationToken = default);
+
+ /// <summary>
+ /// Executes the query and returns whether any document matches it
+ /// </summary>
+ /// <typeparam name="TResult">Type of the query result - the entity itself or a projection</typeparam>
+ /// <param name="query">Query built on top of <see cref="Table" /> or <see cref="TableCollection{C}" /></param>
+ /// <param name="cancellationToken">Cancellation token</param>
+ Task<bool> AnyAsync<TResult>(IQueryable<TResult> query, CancellationToken cancellationToken = default);
+
/// <summary>
/// Executes the query and returns a single page of its results
/// </summary>
diff --git a/src/Core/Grand.Data/LiteDb/LiteDBRepository.cs b/src/Core/Grand.Data/LiteDb/LiteDBRepository.cs
index 2773a2d16..3324079be 100644
--- a/src/Core/Grand.Data/LiteDb/LiteDBRepository.cs
+++ b/src/Core/Grand.Data/LiteDb/LiteDBRepository.cs
@@ -447,6 +447,28 @@ public class LiteDBRepository<T> : IRepository<T> where T : BaseEntity
return Task.FromResult(query.Count());
}
+ /// <summary>
+ /// Executes the query and returns its first result, or the default value when nothing matches
+ /// </summary>
+ public virtual Task<TResult> FirstOrDefaultAsync<TResult>(IQueryable<TResult> query,
+ CancellationToken cancellationToken = default)
+ {
+ ArgumentNullException.ThrowIfNull(query);
+
+ return Task.FromResult(query.FirstOrDefault());
+ }
+
+ /// <summary>
+ /// Executes the query and returns whether any document matches it
+ /// </summary>
+ public virtual Task<bool> AnyAsync<TResult>(IQueryable<TResult> query,
+ CancellationToken cancellationToken = default)
+ {
+ ArgumentNullException.ThrowIfNull(query);
+
+ return Task.FromResult(query.Any());
+ }
+
/// <summary>
/// Executes the query and returns a single page of its results
/// </summary>
diff --git a/src/Core/Grand.Data/Mongo/MongoRepository.cs b/src/Core/Grand.Data/Mongo/MongoRepository.cs
index 69c2116a0..84832a9c2 100644
--- a/src/Core/Grand.Data/Mongo/MongoRepository.cs
+++ b/src/Core/Grand.Data/Mongo/MongoRepository.cs
@@ -369,6 +369,28 @@ public class MongoRepository<T> : IRepository<T> where T : BaseEntity
return await query.CountAsync(cancellationToken);
}
+ /// <summary>
+ /// Executes the query and returns its first result, or the default value when nothing matches
+ /// </summary>
+ public virtual async Task<TResult> FirstOrDefaultAsync<TResult>(IQueryable<TResult> query,
+ CancellationToken cancellationToken = default)
+ {
+ ArgumentNullException.ThrowIfNull(query);
+
+ return await query.FirstOrDefaultAsync(cancellationToken);
+ }
+
+ /// <summary>
+ /// Executes the query and returns whether any document matches it
+ /// </summary>
+ public virtual async Task<bool> AnyAsync<TResult>(IQueryable<TResult> query,
+ CancellationToken cancellationToken = default)
+ {
+ ArgumentNullException.ThrowIfNull(query);
+
+ return await query.AnyAsync(cancellationToken);
+ }
+
/// <summary>
/// Executes the query and returns a single page of its results
/// </summary>
diff --git a/src/Modules/Grand.Module.ScheduledTasks/BackgroundServices/ScheduleTaskService.cs b/src/Modules/Grand.Module.ScheduledTasks/BackgroundServices/ScheduleTaskService.cs
index bc4670bb4..8a5ad31c0 100644
--- a/src/Modules/Grand.Module.ScheduledTasks/BackgroundServices/ScheduleTaskService.cs
+++ b/src/Modules/Grand.Module.ScheduledTasks/BackgroundServices/ScheduleTaskService.cs
@@ -1,4 +1,4 @@
-using Grand.Business.Core.Interfaces.System.ScheduleTasks;
+using Grand.Business.Core.Interfaces.System.ScheduleTasks;
using Grand.Data;
using Grand.Domain.Tasks;
@@ -53,7 +53,7 @@ public class ScheduleTaskService : IScheduleTaskService
/// <returns>Tasks</returns>
public virtual async Task<IList<ScheduleTask>> GetAllTasks()
{
- return await Task.FromResult(_taskRepository.Table.ToList());
+ return await _taskRepository.ToListAsync(_taskRepository.Table);
}
/// <summary>
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryLayoutServiceTest.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryLayoutServiceTest.cs
index 4443810e7..fe10255c3 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryLayoutServiceTest.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryLayoutServiceTest.cs
@@ -38,7 +38,7 @@ public class CategoryLayoutServiceTest
public async Task GetAllCategoryLayouts_InvokeMethods()
{
await _categoryLayoutService.GetAllCategoryLayouts();
- _cacheMock.Verify(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<List<CategoryLayout>>>>()),
+ _cacheMock.Verify(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<IList<CategoryLayout>>>>()),
Times.Once);
}
diff --git a/src/Tests/Grand.Business.Common.Tests/Services/Stores/StoreServiceTests.cs b/src/Tests/Grand.Business.Common.Tests/Services/Stores/StoreServiceTests.cs
index 19d750ab4..9a244c15f 100644
--- a/src/Tests/Grand.Business.Common.Tests/Services/Stores/StoreServiceTests.cs
+++ b/src/Tests/Grand.Business.Common.Tests/Services/Stores/StoreServiceTests.cs
@@ -47,8 +47,8 @@ public class StoreServiceTests
[TestMethod]
public async Task DeleteStore_ValidArgument_InvokeExpectedMethods()
{
- _cacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<List<Store>>>>()))
- .Returns(Task.FromResult(new List<Store> { new(), new() }));
+ _cacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<IList<Store>>>>()))
+ .Returns(Task.FromResult<IList<Store>>(new List<Store> { new(), new() }));
await _service.DeleteStore(new Store());
_repository.Verify(c => c.DeleteAsync(It.IsAny<Store>()), Times.Once);
_mediatorMock.Verify(c => c.Publish(It.IsAny<EntityDeleted<Store>>(), default), Times.Once);
@@ -59,8 +59,8 @@ public class StoreServiceTests
public void DeleteStore_OnlyOneStore_ThrowException()
{
//can not remove store if it is only one
- _cacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<List<Store>>>>()))
- .Returns(Task.FromResult(new List<Store> { new() }));
+ _cacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<IList<Store>>>>()))
+ .Returns(Task.FromResult<IList<Store>>(new List<Store> { new() }));
Assert.ThrowsExactlyAsync<Exception>(async () => await _service.DeleteStore(new Store()));
}
@@ -82,8 +82,8 @@ public class StoreServiceTests
var stores = new List<Store> { store1, store2 };
- _cacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<List<Store>>>>()))
- .Returns(Task.FromResult(stores));
+ _cacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<IList<Store>>>>()))
+ .Returns(Task.FromResult<IList<Store>>(stores));
// Act
var result = await _service.GetStoreByHost("store1.com");
@@ -110,8 +110,8 @@ public class StoreServiceTests
var stores = new List<Store> { store1, store2 };
- _cacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<List<Store>>>>()))
- .Returns(Task.FromResult(stores));
+ _cacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<IList<Store>>>>()))
+ .Returns(Task.FromResult<IList<Store>>(stores));
// Act - host not found in any DomainHost
var result = await _service.GetStoreByHost("nonexisting.com");
diff --git a/src/Tests/Grand.Business.Customers.Tests/Services/CustomerAttributeServiceTests.cs b/src/Tests/Grand.Business.Customers.Tests/Services/CustomerAttributeServiceTests.cs
index 9f1fde811..ae0687b28 100644
--- a/src/Tests/Grand.Business.Customers.Tests/Services/CustomerAttributeServiceTests.cs
+++ b/src/Tests/Grand.Business.Customers.Tests/Services/CustomerAttributeServiceTests.cs
@@ -92,7 +92,7 @@ public class CustomerAttributeServiceTests
public async Task GetAllCustomerAttributes_InvokeRepositoryAndCache()
{
await _atrService.GetAllCustomerAttributes();
- _cacheMock.Verify(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<List<CustomerAttribute>>>>()),
+ _cacheMock.Verify(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<IList<CustomerAttribute>>>>()),
Times.Once);
}
}
\ No newline at end of file
diff --git a/src/Tests/Grand.Data.Tests/RepositoryPagedQueryTests.cs b/src/Tests/Grand.Data.Tests/RepositoryPagedQueryTests.cs
index fd9ebc3b3..ccc7c16c4 100644
--- a/src/Tests/Grand.Data.Tests/RepositoryPagedQueryTests.cs
+++ b/src/Tests/Grand.Data.Tests/RepositoryPagedQueryTests.cs
@@ -153,6 +153,53 @@ public class RepositoryPagedQueryTests
Assert.AreEqual(3, await repository.CountAsync(repository.Table.Where(x => x.Count <= 3)));
}
+ [TestMethod]
+ [DataRow(Mongo)]
+ [DataRow(LiteDb)]
+ public async Task FirstOrDefaultAsync_ReturnsFirstMatchInQueryOrder(string provider)
+ {
+ var repository = Repository(provider);
+
+ var result = await repository.FirstOrDefaultAsync(
+ repository.Table.Where(x => x.Count <= 3).OrderByDescending(x => x.Count));
+
+ Assert.AreEqual(3, result.Count);
+ }
+
+ [TestMethod]
+ [DataRow(Mongo)]
+ [DataRow(LiteDb)]
+ public async Task FirstOrDefaultAsync_NoMatches_ReturnsDefault(string provider)
+ {
+ var repository = Repository(provider);
+
+ Assert.IsNull(await repository.FirstOrDefaultAsync(repository.Table.Where(x => x.Count > 1000)));
+ }
+
+ [TestMethod]
+ [DataRow(Mongo)]
+ [DataRow(LiteDb)]
+ public async Task FirstOrDefaultAsync_Projection_ReturnsProjectedValue(string provider)
+ {
+ var repository = Repository(provider);
+
+ var result =
+ await repository.FirstOrDefaultAsync(repository.Table.OrderBy(x => x.Count).Select(x => x.Name));
+
+ Assert.AreEqual("sample 01", result);
+ }
+
+ [TestMethod]
+ [DataRow(Mongo)]
+ [DataRow(LiteDb)]
+ public async Task AnyAsync_ReturnsWhetherAnythingMatches(string provider)
+ {
+ var repository = Repository(provider);
+
+ Assert.IsTrue(await repository.AnyAsync(repository.Table.Where(x => x.Count <= 3)));
+ Assert.IsFalse(await repository.AnyAsync(repository.Table.Where(x => x.Count > 1000)));
+ }
+
[TestMethod]
[DataRow(Mongo)]
[DataRow(LiteDb)]
@@ -178,5 +225,9 @@ public class RepositoryPagedQueryTests
_mongoRepository.ToListAsync(items.AsQueryable().Where(x => x.Count <= 4)));
await Assert.ThrowsExactlyAsync<ArgumentException>(() =>
_mongoRepository.PagedAsync(items.AsQueryable().OrderBy(x => x.Count), 0, 10));
+ await Assert.ThrowsExactlyAsync<ArgumentException>(() =>
+ _mongoRepository.FirstOrDefaultAsync(items.AsQueryable().Where(x => x.Count <= 4)));
+ await Assert.ThrowsExactlyAsync<ArgumentException>(() =>
+ _mongoRepository.AnyAsync(items.AsQueryable().Where(x => x.Count <= 4)));
}
}
diff --git a/src/Tests/Grand.Web.Common.Tests/Services/Admin/AdminSiteMapServiceTests.cs b/src/Tests/Grand.Web.Common.Tests/Services/Admin/AdminSiteMapServiceTests.cs
index 90e0b9d7e..34abb463a 100644
--- a/src/Tests/Grand.Web.Common.Tests/Services/Admin/AdminSiteMapServiceTests.cs
+++ b/src/Tests/Grand.Web.Common.Tests/Services/Admin/AdminSiteMapServiceTests.cs
@@ -28,8 +28,8 @@ public class AdminSiteMapServiceTests
[TestMethod]
public async Task GetSiteMap_InvokeExpectedMethods()
{
- _cacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<List<AdminSiteMap>>>>()));
+ _cacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<IList<AdminSiteMap>>>>()));
var result = await _service.GetSiteMap();
- _cacheMock.Verify(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<List<AdminSiteMap>>>>()), Times.Once);
+ _cacheMock.Verify(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<IList<AdminSiteMap>>>>()), Times.Once);
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Common/Menu/AdminSiteMapService.cs b/src/Web/Grand.Web.Common/Menu/AdminSiteMapService.cs
index cc6c70455..fd11891ea 100644
--- a/src/Web/Grand.Web.Common/Menu/AdminSiteMapService.cs
+++ b/src/Web/Grand.Web.Common/Menu/AdminSiteMapService.cs
@@ -26,13 +26,13 @@ public class AdminSiteMapService : IAdminSiteMapService
public virtual async Task<IList<AdminSiteMap>> GetSiteMap()
{
- return await _cacheBase.GetAsync(CacheKey.ADMIN_SITEMAP_KEY, () =>
+ return await _cacheBase.GetAsync(CacheKey.ADMIN_SITEMAP_KEY, async () =>
{
var query = from c in _adminSiteMapRepository.Table
orderby c.DisplayOrder
select c;
- return Task.FromResult(query.ToList());
+ return await _adminSiteMapRepository.ToListAsync(query);
});
}
diff --git a/src/Web/Grand.Web.Common/Middleware/InstallUrlMiddleware.cs b/src/Web/Grand.Web.Common/Middleware/InstallUrlMiddleware.cs
index 26e684591..ad7386291 100644
--- a/src/Web/Grand.Web.Common/Middleware/InstallUrlMiddleware.cs
+++ b/src/Web/Grand.Web.Common/Middleware/InstallUrlMiddleware.cs
@@ -73,12 +73,15 @@ public class InstallUrlMiddleware
}
private Task<GrandNodeVersion?> GetDatabaseVersion(HttpContext context, bool databaseIsInstalled)
{
- return _cacheBase.GetAsync(CacheKey.GRAND_NODE_VERSION, () =>
+ return _cacheBase.GetAsync<GrandNodeVersion?>(CacheKey.GRAND_NODE_VERSION, async () =>
{
- if (databaseIsInstalled)
- return Task.FromResult(context.RequestServices.GetRequiredService<IRepository<GrandNodeVersion>>().Table.FirstOrDefault());
+ if (databaseIsInstalled)
+ {
+ var repository = context.RequestServices.GetRequiredService<IRepository<GrandNodeVersion>>();
+ return await repository.FirstOrDefaultAsync(repository.Table);
+ }
- return Task.FromResult<GrandNodeVersion?>(null);
+ return null;
}, int.MaxValue);
}