Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
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.csindex 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 : IExternalAuthenticationServicevar query = from p in _externalAuthenticationRecordRepository.Tablewhere p.CustomerId == customer.Idselect 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.csindex 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 : IBrandLayoutServicevar query = from pt in _brandLayoutRepository.Tableorderby pt.DisplayOrderselect 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.csindex 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 : IBrandServicewhere c.AppliedDiscounts.Any(x => x == discountId)select c;- return await Task.FromResult(query.ToList());+ return await _brandRepository.ToListAsync(query);}#endregiondiff --git a/src/Business/Grand.Business.Catalog/Services/Categories/CategoryLayoutService.cs b/src/Business/Grand.Business.Catalog/Services/Categories/CategoryLayoutService.csindex 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 : ICategoryLayoutServicevar query = from pt in _categoryLayoutRepository.Tableorderby pt.DisplayOrderselect 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.csindex 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 whenstring.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 : ICategoryServicequery = from p in querywhere !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 : ICategoryServicevar 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 : ICategoryServicewhere 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.csindex 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 : ICollectionLayoutServicevar query = from pt in _collectionLayoutRepository.Tableorderby pt.DisplayOrderselect 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.csindex 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 : ICollectionServicevar 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 : ICollectionServicewhere c.AppliedDiscounts.Any(x => x == discountId)select c;- return await Task.FromResult(query.ToList());+ return await _collectionRepository.ToListAsync(query);}#endregiondiff --git a/src/Business/Grand.Business.Catalog/Services/Directory/MeasureService.cs b/src/Business/Grand.Business.Catalog/Services/Directory/MeasureService.csindex 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 : IMeasureServicevar query = from md in _measureDimensionRepository.Tableorderby md.DisplayOrderselect md;- return await Task.FromResult(query.ToList());+ return await _measureDimensionRepository.ToListAsync(query);});}@@ -250,7 +250,7 @@ public class MeasureService : IMeasureServicevar query = from mw in _measureWeightRepository.Tableorderby mw.DisplayOrderselect mw;- return await Task.FromResult(query.ToList());+ return await _measureWeightRepository.ToListAsync(query);});}@@ -391,7 +391,7 @@ public class MeasureService : IMeasureServicevar query = from md in _measureUnitRepository.Tableorderby md.DisplayOrderselect 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.csindex 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 : ISearchTermServicevar query = from st in _searchTermRepository.Tablewhere st.Keyword == keyword && st.StoreId == storeIdselect 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.csindex 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 : IDiscountServicequery = 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.csindex 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 : IDiscountValidationServiceif (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 filediff --git a/src/Business/Grand.Business.Catalog/Services/Products/AuctionService.cs b/src/Business/Grand.Business.Catalog/Services/Products/AuctionService.csindex 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 : IAuctionServicepublic 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.csindex 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 : ICustomerGroupProductServicevar 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 : ICustomerGroupProductServiceorderby cr.DisplayOrderselect cr;- return await Task.FromResult(query.FirstOrDefault());+ return await _customerGroupProductRepository.FirstOrDefaultAsync(query);}#endregiondiff --git a/src/Business/Grand.Business.Catalog/Services/Products/InventoryManageService.cs b/src/Business/Grand.Business.Catalog/Services/Products/InventoryManageService.csindex 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 : IInventoryManageServicewhere j.ProductId == product.Id && j.PositionId == shipmentItem.Idselect 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.csindex 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 : IOutOfStockSubscriptionServicebiss.WarehouseId == warehouseIdselect 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.csindex 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 : IProductLayoutServicevar query = from pt in _productLayoutRepository.Tableorderby pt.DisplayOrderselect 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.csindex 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 filediff --git a/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductService.csindex 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 : IProductServicevar 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.csindex 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 : IProductTagServicepublic 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.csindex 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 : IRecentlyViewedProductsServicewhere p.CustomerId == customerIdorderby p.CreatedOnUtc descendingselect 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.csindex 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 : ISpecificationAttributeServicevar 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 : ISpecificationAttributeServicevar query = from p in _specificationAttributeRepository.Tablewhere 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.csindex 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 : ITaxCategoryServicevar 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.csindex 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<GetMerchandpublic 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 filediff --git a/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeService.cs b/src/Business/Grand.Business.Checkout/Services/CheckoutAttributes/CheckoutAttributeService.csindex 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.csindex 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 : IGiftVoucherServiceselect 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 : IGiftVoucherServicegc.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.csindex 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 CreatedOnUtcquery = 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 : ILoyaltyPointsServicequery = 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);}#endregiondiff --git a/src/Business/Grand.Business.Checkout/Services/Orders/MerchandiseReturnService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/MerchandiseReturnService.csindex 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 : IMerchandiseReturnServiceorderby merchandiseReturnNote.CreatedOnUtc descendingselect 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));}#endregiondiff --git a/src/Business/Grand.Business.Checkout/Services/Orders/OrderService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/OrderService.csindex 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.Tablewhere 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 : IOrderServiceif (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 : IOrderServicevar query = from o in _orderRepository.Tablewhere orderIds.Contains(o.Id)select o;- var orders = await Task.FromResult(query.ToList());+ var orders = await _orderRepository.ToListAsync(query);//sort by passed identifiersreturn 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.Tablewhere o.OrderGuid == orderGuidselect 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.Tablefrom orderItem in order.OrderItems@@ -268,7 +270,7 @@ public class OrderService : IOrderServicewhere orderItem.OrderItemGuid == orderItemGuidselect orderItem;- return Task.FromResult(query.FirstOrDefault());+ return await _orderRepository.FirstOrDefaultAsync(query);}#endregion@@ -310,7 +312,7 @@ public class OrderService : IOrderServiceorderby orderNote.CreatedOnUtc descendingselect 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));}#endregiondiff --git a/src/Business/Grand.Business.Checkout/Services/Orders/OrderStatusService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/OrderStatusService.csindex 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 : IOrderStatusServiceselect 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.csindex 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.csindex 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 : IPaymentTransactionServiceif (!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.csindex 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 : IShipmentServicevar query = from o in _shipmentRepository.Tablewhere 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 : IShipmentServiceorderby shipmentNote.CreatedOnUtc descendingselect 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));}#endregiondiff --git a/src/Business/Grand.Business.Checkout/Services/Shipping/ShippingMethodService.cs b/src/Business/Grand.Business.Checkout/Services/Shipping/ShippingMethodService.csindex 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 : IShippingMethodServicequery = 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.csindex 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 : IBlogServicewhere (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 : IBlogServiceorderby c.CreatedOnUtcselect 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 : IBlogServiceif (!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 : IBlogServiceorderby bp.DisplayOrderselect bp;- return await Task.FromResult(query.ToList());+ return await _blogProductRepository.ToListAsync(query);}#endregiondiff --git a/src/Business/Grand.Business.Cms/Services/KnowledgebaseService.cs b/src/Business/Grand.Business.Cms/Services/KnowledgebaseService.csindex 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 : IKnowledgebaseServicequery = 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 : IKnowledgebaseServiceselect 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 : IKnowledgebaseServicepublic 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 : IKnowledgebaseServicequery = 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 : IKnowledgebaseServicequery = 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 : IKnowledgebaseServicequery = 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 : IKnowledgebaseServicequery = 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 : IKnowledgebaseServicequery = 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 : IKnowledgebaseServicequery = 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 : IKnowledgebaseServicequery = 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 : IKnowledgebaseServicewhere c.ArticleId == articleIdorderby c.CreatedOnUtcselect 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 : IKnowledgebaseServiceorderby c.CreatedOnUtcwhere customerId == "" || c.CustomerId == customerIdselect 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.csindex 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 : INewsServicewhere customerId == "" || c.CustomerId == customerIdselect c;- return await Task.FromResult(query2.ToList());+ return await _newsItemRepository.ToListAsync(query2);}#endregiondiff --git a/src/Business/Grand.Business.Cms/Services/PageLayoutService.cs b/src/Business/Grand.Business.Cms/Services/PageLayoutService.csindex 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 : IPageLayoutServiceorderby pt.DisplayOrderselect 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.csindex 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 : IAddressAttributeServicewhere !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.csindex 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 : ICountryServicewhere !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 : ICountryServicevar query = from c in _countryRepository.Tablewhere countryIds.Contains(c.Id)select c;- var countries = await Task.FromResult(query.ToList());+ var countries = await _countryRepository.ToListAsync(query);//sort by passed identifiersreturn 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.csindex 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 : ICurrencyServicevar query = from q in _currencyRepository.Tablewhere 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 : ICurrencyServiceif (!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 acldiff --git a/src/Business/Grand.Business.Common/Services/Directory/GroupService.cs b/src/Business/Grand.Business.Common/Services/Directory/GroupService.csindex 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 : IGroupServicevar 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 : IGroupServicevar query = from cr in _customerGroupRepository.Tableorderby cr.Nameselect 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.csindex 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 filediff --git a/src/Business/Grand.Business.Common/Services/Localization/LanguageService.cs b/src/Business/Grand.Business.Common/Services/Localization/LanguageService.csindex 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 : ILanguageServiceif (!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 : ILanguageServicevar query = from q in _languageRepository.Tablewhere 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.csindex 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 : ITranslationServiceorderby lsr.Namewhere lsr.LanguageId == languageId && lsr.Name == nameselect 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.csindex 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 : IPermissionServicereturn 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 : IPermissionServicewhere pr.SystemName == systemNameselect pr;- return await Task.FromResult(query.FirstOrDefault());+ return await _permissionRepository.FirstOrDefaultAsync(query);}/// <summary>@@ -126,7 +126,7 @@ public class PermissionService : IPermissionServicevar query = from pr in _permissionRepository.Tableorderby pr.Nameselect 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 : IPermissionServicepermissionActionName);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.csindex 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 : ISlugServicewhere ur.Slug == slugorderby ur.IsActiveselect ur;- return await Task.FromResult(query.FirstOrDefault());+ return await _urlEntityRepository.FirstOrDefaultAsync(query);}/// <summary>@@ -170,7 +170,7 @@ public class SlugService : ISlugServiceur.LanguageId == languageId &&ur.IsActiveselect 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.csindex 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 enableusing 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.csindex 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 : IAffiliateServicevar query = from a in _affiliateRepository.Tablewhere 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.csindex 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 : ICustomerAttributeServicewhere !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.csindex 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 filediff --git a/src/Business/Grand.Business.Customers/Services/CustomerNoteService.cs b/src/Business/Grand.Business.Customers/Services/CustomerNoteService.csindex 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 : ICustomerNoteServicequery = query.OrderByDescending(x => x.CreatedOnUtc);- return await Task.FromResult(query.ToList());+ return await _customerNoteRepository.ToListAsync(query);}#endregiondiff --git a/src/Business/Grand.Business.Customers/Services/CustomerService.cs b/src/Business/Grand.Business.Customers/Services/CustomerService.csindex 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 : ICustomerServiceif (!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.csindex 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 : ISalesEmployeeServicevar query = from se in _salesEmployeeRepository.Tableorderby se.DisplayOrderselect 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.csindex 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.csindex 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 : IVendorServicevar query = from c in _vendorRepository.Tablewhere 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 : IVendorServicequery = query.Where(p => p.Name.ToLower().Contains(keywords.ToLower()));//vendor filteringif (!string.IsNullOrEmpty(vendorId)) query = query.Where(x => x.Id == vendorId);- return await Task.FromResult(query.ToList());+ return await _vendorRepository.ToListAsync(query);}#endregiondiff --git a/src/Business/Grand.Business.Marketing/Services/Campaigns/CampaignService.cs b/src/Business/Grand.Business.Marketing/Services/Campaigns/CampaignService.csindex 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.Tableorderby c.CreatedOnUtcselect 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.csindex 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 : IContactAttributeServicequery = 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 : IContactAttributeServicequery = from p in querywhere !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.csindex 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 : ICourseActionServicewhere a.CustomerId == customerId && a.LessonId == lessonIdselect 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.Tablewhere 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.csindex 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 : ICourseLessonServicewhere c.CourseId == courseIdselect 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.csindex 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 : ICourseLevelServiceorderby l.DisplayOrderselect 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.csindex 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 : ICourseSubjectServiceorderby c.DisplayOrderselect 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.csindex 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 : ICustomerProductServicevar 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 : ICustomerProductServicewhere pp.CustomerId == customerId && pp.ProductId == productIdselect 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.csindex 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 : ICustomerTagServicewhere pt.Name == nameselect pt;- return await Task.FromResult(query.FirstOrDefault());+ return await _customerTagRepository.FirstOrDefaultAsync(query);}/// <summary>@@ -109,7 +109,7 @@ public class CustomerTagService : ICustomerTagServicevar query = from pt in _customerTagRepository.Tablewhere 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 : ICustomerTagServicewhere cr.CustomerTagId == customerTagIdorderby cr.DisplayOrderselect cr;- return await Task.FromResult(query.ToList());+ return await _customerTagProductRepository.ToListAsync(query);});}@@ -211,7 +211,7 @@ public class CustomerTagService : ICustomerTagServicewhere cr.CustomerTagId == customerTagId && cr.ProductId == productIdorderby cr.DisplayOrderselect 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.csindex 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 : IDocumentTypeServicevar query = from t in _documentTypeRepository.Tableorderby t.DisplayOrderselect 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.csindex 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 : INewsletterCategoryServicewhere !p.LimitedToStores || p.Stores.Contains(storeId)orderby p.DisplayOrderselect p;- return await Task.FromResult(query.ToList());+ return await _newsletterCategoryRepository.ToListAsync(query);}#endregiondiff --git a/src/Business/Grand.Business.Marketing/Services/PushNotifications/PushNotificationsService.cs b/src/Business/Grand.Business.Marketing/Services/PushNotifications/PushNotificationsService.csindex 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.csindex 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<GetBidsByProductIdpublic 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 filediff --git a/src/Business/Grand.Business.Storage/Services/PictureService.cs b/src/Business/Grand.Business.Storage/Services/PictureService.csindex 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 : IPictureServiceStyle = 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.csindex 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.csindex 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 : BaseEntityreturn 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.csindex 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 : BaseEntityreturn 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.csindex 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.csindex 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 CategoryLayoutServiceTestpublic 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.csindex 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 StoreServiceTestspublic 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 StoreServiceTestsvar 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));// Actvar result = await _service.GetStoreByHost("store1.com");@@ -110,8 +110,8 @@ public class StoreServiceTestsvar 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 DomainHostvar 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.csindex 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 CustomerAttributeServiceTestspublic 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 filediff --git a/src/Tests/Grand.Data.Tests/RepositoryPagedQueryTests.cs b/src/Tests/Grand.Data.Tests/RepositoryPagedQueryTests.csindex 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 RepositoryPagedQueryTestsAssert.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.csindex 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 filediff --git a/src/Web/Grand.Web.Common/Menu/AdminSiteMapService.cs b/src/Web/Grand.Web.Common/Menu/AdminSiteMapService.csindex 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 : IAdminSiteMapServicepublic 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.Tableorderby c.DisplayOrderselect 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.csindex 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);}