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
Refactoring - use repository extensions (catalog services)
KrzysztofPajakc08b51dd60ac
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/CustomerGroupProductService.cs b/src/Business/Grand.Business.Catalog/Services/Products/CustomerGroupProductService.csindex 12658c0d8..ad8728252 100644--- a/src/Business/Grand.Business.Catalog/Services/Products/CustomerGroupProductService.cs+++ b/src/Business/Grand.Business.Catalog/Services/Products/CustomerGroupProductService.cs@@ -5,11 +5,10 @@ using Grand.Infrastructure.Caching;using Grand.Infrastructure.Caching.Constants;using Grand.Infrastructure.Extensions;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;using System;using System.Collections.Generic;using System.Threading.Tasks;+using System.Linq;namespace Grand.Business.Catalog.Services.Products{@@ -79,11 +78,7 @@ namespace Grand.Business.Catalog.Services.Productsif (customerGroupProduct == null)throw new ArgumentNullException(nameof(customerGroupProduct));- var builder = Builders<CustomerGroupProduct>.Filter;- var filter = builder.Eq(x => x.Id, customerGroupProduct.Id);- var update = Builders<CustomerGroupProduct>.Update- .Set(x => x.DisplayOrder, customerGroupProduct.DisplayOrder);- await _customerGroupProductRepository.Collection.UpdateOneAsync(filter, update);+ await _customerGroupProductRepository.UpdateAsync(customerGroupProduct);//clear cacheawait _cacheBase.RemoveAsync(string.Format(CacheKey.CUSTOMERGROUPSPRODUCTS_ROLE_KEY, customerGroupProduct.CustomerGroupId));@@ -104,8 +99,7 @@ namespace Grand.Business.Catalog.Services.Productsstring key = string.Format(CacheKey.CUSTOMERGROUPSPRODUCTS_ROLE_KEY, customerGroupId);return await _cacheBase.GetAsync(key, () =>{- var filter = Builders<CustomerGroupProduct>.Filter.Eq(x => x.CustomerGroupId, customerGroupId);- return _customerGroupProductRepository.Collection.Find(filter).SortBy(x => x.DisplayOrder).ToListAsync();+ return _customerGroupProductRepository.Table.Where(x => x.CustomerGroupId == customerGroupId).OrderBy(x => x.DisplayOrder).ToListAsync2();});}@@ -117,11 +111,9 @@ namespace Grand.Business.Catalog.Services.Products/// <returns>Customer group product</returns>public virtual Task<CustomerGroupProduct> GetCustomerGroupProduct(string customerGroupId, string productId){- var filters = Builders<CustomerGroupProduct>.Filter;- var filter = filters.Eq(x => x.CustomerGroupId, customerGroupId);- filter &= filters.Eq(x => x.ProductId, productId);-- return _customerGroupProductRepository.Collection.Find(filter).SortBy(x => x.DisplayOrder).FirstOrDefaultAsync();+ return _customerGroupProductRepository.Table+ .Where(x => x.CustomerGroupId == customerGroupId && x.ProductId == productId)+ .OrderBy(x => x.DisplayOrder).FirstOrDefaultAsync2();}/// <summary>@@ -136,7 +128,7 @@ namespace Grand.Business.Catalog.Services.Productsorderby cr.DisplayOrderselect cr;- return query.FirstOrDefaultAsync();+ return query.FirstOrDefaultAsync2();}diff --git a/src/Business/Grand.Business.Catalog/Services/Products/InventoryManageService.cs b/src/Business/Grand.Business.Catalog/Services/Products/InventoryManageService.csindex 34f8fd7c6..7b5045f40 100644--- a/src/Business/Grand.Business.Catalog/Services/Products/InventoryManageService.cs+++ b/src/Business/Grand.Business.Catalog/Services/Products/InventoryManageService.cs@@ -9,8 +9,6 @@ using Grand.Infrastructure.Caching;using Grand.Infrastructure.Caching.Constants;using Grand.Infrastructure.Extensions;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;using System;using System.Collections.Generic;using System.Linq;@@ -67,14 +65,8 @@ namespace Grand.Business.Catalog.Services.Productspwi.ReservedQuantity -= shipmentItem.Quantity;pwi.StockQuantity -= shipmentItem.Quantity;- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, product.Id);- filter &= builder.Where(x => x.ProductWarehouseInventory.Any(y => y.WarehouseId == pwi.WarehouseId));-- var update = Builders<Product>.Update- .Set(x => x.ProductWarehouseInventory.ElementAt(-1), pwi)- .CurrentDate("UpdatedOnUtc");- await _productRepository.Collection.UpdateOneAsync(filter, update);+ await _productRepository.UpdateToSet(product.Id, x => x.ProductWarehouseInventory, z => z.Id, pwi.Id, pwi);+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);product.StockQuantity = product.ProductWarehouseInventory.Sum(x => x.StockQuantity);product.ReservedQuantity = product.ProductWarehouseInventory.Sum(x => x.ReservedQuantity);@@ -97,18 +89,8 @@ namespace Grand.Business.Catalog.Services.Products{combination.ReservedQuantity -= shipmentItem.Quantity;combination.StockQuantity -= shipmentItem.Quantity;-- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, product.Id);- filter &= builder.ElemMatch(x => x.ProductAttributeCombinations, y => y.Id == combination.Id);- var update = Builders<Product>.Update- .Set("ProductAttributeCombinations.$.StockQuantity", combination.StockQuantity)- .Set("ProductAttributeCombinations.$.ReservedQuantity", combination.ReservedQuantity)- .Set("ProductAttributeCombinations.$.WarehouseInventory", combination.WarehouseInventory)- .CurrentDate("UpdatedOnUtc");-- await _productRepository.Collection.UpdateManyAsync(filter, update);-+ await _productRepository.UpdateToSet(product.Id, x => x.ProductAttributeCombinations, z => z.Id, combination.Id, combination);+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);}else{@@ -122,16 +104,9 @@ namespace Grand.Business.Catalog.Services.Productscombination.StockQuantity = combination.WarehouseInventory.Sum(x => x.StockQuantity);combination.ReservedQuantity = combination.WarehouseInventory.Sum(x => x.ReservedQuantity);- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, product.Id);- filter &= builder.ElemMatch(x => x.ProductAttributeCombinations, y => y.Id == combination.Id);- var update = Builders<Product>.Update- .Set("ProductAttributeCombinations.$.StockQuantity", combination.StockQuantity)- .Set("ProductAttributeCombinations.$.ReservedQuantity", combination.ReservedQuantity)- .Set("ProductAttributeCombinations.$.WarehouseInventory", combination.WarehouseInventory)- .CurrentDate("UpdatedOnUtc");+ await _productRepository.UpdateToSet(product.Id, x => x.ProductAttributeCombinations, z => z.Id, combination.Id, combination);+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);- await _productRepository.Collection.UpdateManyAsync(filter, update);}product.StockQuantity = product.ProductAttributeCombinations.Sum(x => x.StockQuantity);product.ReservedQuantity = product.ProductAttributeCombinations.Sum(x => x.ReservedQuantity);@@ -198,7 +173,7 @@ namespace Grand.Business.Catalog.Services.Productswhere j.ProductId == product.Id && j.PositionId == shipmentItem.Idselect j.Id;- return await query.AnyAsync();+ return await Task.FromResult(query.Any());}private async Task ReverseBookedInventory(Product product, InventoryJournal inventoryJournal){@@ -214,14 +189,9 @@ namespace Grand.Business.Catalog.Services.Productspwi.StockQuantity += inventoryJournal.OutQty;pwi.ReservedQuantity += inventoryJournal.OutQty;- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, product.Id);- filter &= builder.Where(x => x.ProductWarehouseInventory.Any(y => y.WarehouseId == pwi.WarehouseId));+ await _productRepository.UpdateToSet(product.Id, x => x.ProductWarehouseInventory, z => z.Id, pwi.Id, pwi);+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);- var update = Builders<Product>.Update- .Set(x => x.ProductWarehouseInventory.ElementAt(-1), pwi)- .CurrentDate("UpdatedOnUtc");- await _productRepository.Collection.UpdateOneAsync(filter, update);}else{@@ -245,17 +215,11 @@ namespace Grand.Business.Catalog.Services.Productsproduct.StockQuantity = product.ProductAttributeCombinations.Sum(x => x.StockQuantity);product.ReservedQuantity = product.ProductAttributeCombinations.Sum(x => x.ReservedQuantity);- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, product.Id);- filter &= builder.ElemMatch(x => x.ProductAttributeCombinations, y => y.Id == combination.Id);- var update = Builders<Product>.Update- .Set(x => x.StockQuantity, product.StockQuantity)- .Set(x => x.ReservedQuantity, product.ReservedQuantity)- .Set("ProductAttributeCombinations.$.StockQuantity", combination.StockQuantity)- .Set("ProductAttributeCombinations.$.ReservedQuantity", combination.ReservedQuantity)- .CurrentDate("UpdatedOnUtc");+ await _productRepository.UpdateToSet(product.Id, x => x.ProductAttributeCombinations, z => z.Id, combination.Id, combination);+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);++ await UpdateStockProduct(product);- await _productRepository.Collection.UpdateManyAsync(filter, update);}else@@ -271,19 +235,11 @@ namespace Grand.Business.Catalog.Services.Productscombination.ReservedQuantity = combination.WarehouseInventory.Sum(x => x.StockQuantity);product.StockQuantity = product.ProductAttributeCombinations.Sum(x => x.StockQuantity);product.ReservedQuantity = product.ProductAttributeCombinations.Sum(x => x.ReservedQuantity);++ await _productRepository.UpdateToSet(product.Id, x => x.ProductAttributeCombinations, z => z.Id, combination.Id, combination);+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);+ await UpdateStockProduct(product);- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, product.Id);- filter &= builder.ElemMatch(x => x.ProductAttributeCombinations, y => y.Id == combination.Id);- var update = Builders<Product>.Update- .Set(x => x.StockQuantity, product.StockQuantity)- .Set(x => x.ReservedQuantity, product.ReservedQuantity)- .Set("ProductAttributeCombinations.$.StockQuantity", combination.StockQuantity)- .Set("ProductAttributeCombinations.$.ReservedQuantity", combination.ReservedQuantity)- .Set("ProductAttributeCombinations.$.WarehouseInventory", combination.WarehouseInventory)- .CurrentDate("UpdatedOnUtc");-- await _productRepository.Collection.UpdateManyAsync(filter, update);}}@@ -352,12 +308,9 @@ namespace Grand.Business.Catalog.Services.Productsproduct.DisableBuyButton = true;product.LowStock = true;- var filter = Builders<Product>.Filter.Eq("Id", product.Id);- var update = Builders<Product>.Update- .Set(x => x.DisableBuyButton, product.DisableBuyButton)- .Set(x => x.LowStock, product.LowStock)- .CurrentDate("UpdatedOnUtc");- await _productRepository.Collection.UpdateOneAsync(filter, update);+ await _productRepository.UpdateField(product.Id, x => x.DisableBuyButton, product.DisableBuyButton);+ await _productRepository.UpdateField(product.Id, x => x.LowStock, product.LowStock);+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, product.Id));@@ -368,12 +321,10 @@ namespace Grand.Business.Catalog.Services.Productscase LowStockActivity.Unpublish:product.Published = false;product.LowStock = true;- var filter2 = Builders<Product>.Filter.Eq("Id", product.Id);- var update2 = Builders<Product>.Update- .Set(x => x.Published, product.Published)- .Set(x => x.LowStock, product.LowStock)- .CurrentDate("UpdatedOnUtc");- await _productRepository.Collection.UpdateOneAsync(filter2, update2);++ await _productRepository.UpdateField(product.Id, x => x.Published, product.Published);+ await _productRepository.UpdateField(product.Id, x => x.LowStock, product.LowStock);+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, product.Id));@@ -401,12 +352,9 @@ namespace Grand.Business.Catalog.Services.Productsproduct.DisableBuyButton = false;product.LowStock = product.MinStockQuantity <= totalStock;- var filter = Builders<Product>.Filter.Eq("Id", product.Id);- var update = Builders<Product>.Update- .Set(x => x.DisableBuyButton, product.DisableBuyButton)- .Set(x => x.LowStock, product.LowStock)- .CurrentDate("UpdatedOnUtc");- await _productRepository.Collection.UpdateOneAsync(filter, update);+ await _productRepository.UpdateField(product.Id, x => x.DisableBuyButton, product.DisableBuyButton);+ await _productRepository.UpdateField(product.Id, x => x.LowStock, product.LowStock);+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, product.Id));@@ -419,12 +367,9 @@ namespace Grand.Business.Catalog.Services.Productsproduct.Published = true;product.LowStock = product.MinStockQuantity < totalStock;- var filter2 = Builders<Product>.Filter.Eq("Id", product.Id);- var update2 = Builders<Product>.Update- .Set(x => x.Published, product.Published)- .Set(x => x.LowStock, product.LowStock)- .CurrentDate("UpdatedOnUtc");- await _productRepository.Collection.UpdateOneAsync(filter2, update2);+ await _productRepository.UpdateField(product.Id, x => x.Published, product.Published);+ await _productRepository.UpdateField(product.Id, x => x.LowStock, product.LowStock);+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, product.Id));@@ -533,11 +478,9 @@ namespace Grand.Business.Catalog.Services.Productspwi.ReservedQuantity += qty;- var filter = Builders<Product>.Filter.Eq("Id", product.Id);- var update = Builders<Product>.Update- .Set(x => x.ProductWarehouseInventory, product.ProductWarehouseInventory)- .CurrentDate("UpdatedOnUtc");- await _productRepository.Collection.UpdateOneAsync(filter, update);+ await _productRepository.UpdateToSet(product.Id, x => x.ProductWarehouseInventory, z => z.Id, pwi.Id, pwi);+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);+}//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, product.Id));@@ -570,16 +513,10 @@ namespace Grand.Business.Catalog.Services.Products{combination.ReservedQuantity += qty;product.ReservedQuantity = product.ProductAttributeCombinations.Sum(x => x.ReservedQuantity);-- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, product.Id);- filter &= builder.ElemMatch(x => x.ProductAttributeCombinations, y => y.Id == combination.Id);- var update = Builders<Product>.Update- .Set(x => x.ReservedQuantity, product.ReservedQuantity)- .Set("ProductAttributeCombinations.$.ReservedQuantity", combination.ReservedQuantity)- .CurrentDate("UpdatedOnUtc");-- await _productRepository.Collection.UpdateManyAsync(filter, update);++ await _productRepository.UpdateToSet(product.Id, x => x.ProductAttributeCombinations, z => z.Id, combination.Id, combination);+ await _productRepository.UpdateField(product.Id, x => x.ReservedQuantity, product.ReservedQuantity);+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);}else@@ -595,17 +532,9 @@ namespace Grand.Business.Catalog.Services.Productsproduct.ReservedQuantity = product.ProductAttributeCombinations.Sum(x => x.ReservedQuantity);- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, product.Id);- filter &= builder.ElemMatch(x => x.ProductAttributeCombinations, y => y.Id == combination.Id);- var update = Builders<Product>.Update- .Set(x => x.ReservedQuantity, product.ReservedQuantity)- .Set("ProductAttributeCombinations.$.StockQuantity", combination.StockQuantity)- .Set("ProductAttributeCombinations.$.ReservedQuantity", combination.ReservedQuantity)- .Set("ProductAttributeCombinations.$.WarehouseInventory", combination.WarehouseInventory)- .CurrentDate("UpdatedOnUtc");-- await _productRepository.Collection.UpdateManyAsync(filter, update);+ await _productRepository.UpdateToSet(product.Id, x => x.ProductAttributeCombinations, z => z.Id, combination.Id, combination);+ await _productRepository.UpdateField(product.Id, x => x.ReservedQuantity, product.ReservedQuantity);+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);}//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, product.Id));@@ -645,11 +574,9 @@ namespace Grand.Business.Catalog.Services.Productspwi.ReservedQuantity -= qty;- var filter = Builders<Product>.Filter.Eq("Id", product.Id);- var update = Builders<Product>.Update- .Set(x => x.ProductWarehouseInventory, product.ProductWarehouseInventory)- .CurrentDate("UpdatedOnUtc");- await _productRepository.Collection.UpdateOneAsync(filter, update);+ await _productRepository.UpdateToSet(product.Id, x => x.ProductWarehouseInventory, z => z.Id, pwi.Id, pwi);+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);+}//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, product.Id));@@ -677,15 +604,10 @@ namespace Grand.Business.Catalog.Services.Products{combination.ReservedQuantity -= qty;product.ReservedQuantity = product.ProductAttributeCombinations.Sum(x => x.ReservedQuantity);- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, product.Id);- filter &= builder.ElemMatch(x => x.ProductAttributeCombinations, y => y.Id == combination.Id);- var update = Builders<Product>.Update- .Set(x => x.ReservedQuantity, product.ReservedQuantity)- .Set("ProductAttributeCombinations.$.ReservedQuantity", combination.ReservedQuantity)- .CurrentDate("UpdatedOnUtc");- await _productRepository.Collection.UpdateManyAsync(filter, update);+ await _productRepository.UpdateToSet(product.Id, x => x.ProductAttributeCombinations, z => z.Id, combination.Id, combination);+ await _productRepository.UpdateField(product.Id, x => x.ReservedQuantity, product.ReservedQuantity);+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);}else@@ -697,15 +619,9 @@ namespace Grand.Business.Catalog.Services.Productspwi.ReservedQuantity -= qty;combination.ReservedQuantity = combination.WarehouseInventory.Sum(x => x.ReservedQuantity);- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, product.Id);- filter = filter & builder.ElemMatch(x => x.ProductAttributeCombinations, y => y.Id == combination.Id);- var update = Builders<Product>.Update- .Set("ProductAttributeCombinations.$.ReservedQuantity", combination.ReservedQuantity)- .Set("ProductAttributeCombinations.$.WarehouseInventory", combination.WarehouseInventory)- .CurrentDate("UpdatedOnUtc");+ await _productRepository.UpdateToSet(product.Id, x => x.ProductAttributeCombinations, z => z.Id, combination.Id, combination);+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);- await _productRepository.Collection.UpdateManyAsync(filter, update);}//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, product.Id));@@ -807,13 +723,11 @@ namespace Grand.Business.Catalog.Services.Productsthrow new ArgumentNullException(nameof(product));//update- var filter = Builders<Product>.Filter.Eq("Id", product.Id);- var update = Builders<Product>.Update- .Set(x => x.StockQuantity, product.StockQuantity)- .Set(x => x.ReservedQuantity, product.ReservedQuantity)- .Set(x => x.LowStock, ((product.MinStockQuantity > 0 && product.MinStockQuantity >= product.StockQuantity - product.ReservedQuantity) || product.StockQuantity - product.ReservedQuantity <= 0))- .CurrentDate("UpdatedOnUtc");- await _productRepository.Collection.UpdateOneAsync(filter, update);+ await _productRepository.UpdateField(product.Id, x => x.StockQuantity, product.StockQuantity);+ await _productRepository.UpdateField(product.Id, x => x.ReservedQuantity, product.ReservedQuantity);+ await _productRepository.UpdateField(product.Id, x => x.LowStock, ((product.MinStockQuantity > 0 && product.MinStockQuantity >= product.StockQuantity - product.ReservedQuantity) || product.StockQuantity - product.ReservedQuantity <= 0));+ await _productRepository.UpdateField(product.Id, x => x.UpdatedOnUtc, DateTime.UtcNow);+//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, product.Id));diff --git a/src/Business/Grand.Business.Catalog/Services/Products/OutOfStockSubscriptionService.cs b/src/Business/Grand.Business.Catalog/Services/Products/OutOfStockSubscriptionService.csindex 09a0da097..45d3a90fe 100644--- a/src/Business/Grand.Business.Catalog/Services/Products/OutOfStockSubscriptionService.cs+++ b/src/Business/Grand.Business.Catalog/Services/Products/OutOfStockSubscriptionService.cs@@ -6,8 +6,6 @@ using Grand.Domain.Catalog;using Grand.Domain.Common;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;using System;using System.Collections.Generic;using System.Linq;@@ -58,7 +56,8 @@ namespace Grand.Business.Catalog.Services.Productspublic virtual async Task<IPagedList<OutOfStockSubscription>> GetAllSubscriptionsByCustomerId(string customerId,string storeId = "", int pageIndex = 0, int pageSize = int.MaxValue){- var query = _outOfStockSubscriptionRepository.Table;+ var query = from p in _outOfStockSubscriptionRepository.Table+ select p;//customerquery = query.Where(biss => biss.CustomerId == customerId);@@ -92,7 +91,7 @@ namespace Grand.Business.Catalog.Services.Productsbiss.WarehouseId == warehouseIdselect biss;- var outOfStockSubscriptionlist = await query.ToListAsync();+ var outOfStockSubscriptionlist = await query.ToListAsync2();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/ProductCourseService.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductCourseService.csindex 0c08c2abb..832e961c1 100644--- a/src/Business/Grand.Business.Catalog/Services/Products/ProductCourseService.cs+++ b/src/Business/Grand.Business.Catalog/Services/Products/ProductCourseService.cs@@ -2,9 +2,9 @@using Grand.Domain.Catalog;using Grand.Domain.Courses;using Grand.Domain.Data;-using MongoDB.Driver;using System;using System.Threading.Tasks;+using System.Linq;namespace Grand.Business.Catalog.Services.Products{@@ -21,22 +21,12 @@ namespace Grand.Business.Catalog.Services.Productspublic virtual async Task<Course> GetCourseByProductId(string productId){- var builder = Builders<Course>.Filter;- var filter = FilterDefinition<Course>.Empty;-- filter = filter & builder.Where(p => p.ProductId == productId);-- return await _courseRepository.Collection.Find(filter).FirstOrDefaultAsync();+ return await _courseRepository.Table.Where(p => p.ProductId == productId).FirstOrDefaultAsync2();}public virtual async Task<Product> GetProductByCourseId(string courseId){- var builder = Builders<Product>.Filter;- var filter = FilterDefinition<Product>.Empty;-- filter = filter & builder.Where(p => p.CourseId == courseId);-- return await _productRepository.Collection.Find(filter).FirstOrDefaultAsync();+ return await _productRepository.Table.Where(p => p.CourseId == courseId).FirstOrDefaultAsync2();}public virtual async Task UpdateCourseOnProduct(string productId, string courseId)@@ -44,13 +34,8 @@ namespace Grand.Business.Catalog.Services.Productsif (string.IsNullOrEmpty(productId))throw new ArgumentNullException("productId");- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, productId);- var update = Builders<Product>.Update- .Set(x => x.CourseId, courseId)- .CurrentDate("UpdatedOnUtc");-- await _productRepository.Collection.UpdateOneAsync(filter, update);+ await _productRepository.UpdateField(productId, x => x.CourseId, courseId);+ await _productRepository.UpdateField(productId, x => x.UpdatedOnUtc, DateTime.UtcNow);}}}diff --git a/src/Business/Grand.Business.Catalog/Services/Products/ProductLayoutService.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductLayoutService.csindex d82e1a7f6..c505ddaf6 100644--- a/src/Business/Grand.Business.Catalog/Services/Products/ProductLayoutService.cs+++ b/src/Business/Grand.Business.Catalog/Services/Products/ProductLayoutService.cs@@ -3,8 +3,6 @@ using Grand.Infrastructure.Extensions;using Grand.Domain.Catalog;using Grand.Domain.Data;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;using System;using System.Collections.Generic;using System.Linq;@@ -60,7 +58,7 @@ namespace Grand.Business.Catalog.Services.Productsvar query = from pt in _productLayoutRepository.Tableorderby pt.DisplayOrderselect pt;- return query.ToListAsync();+ return query.ToListAsync2();});}diff --git a/src/Business/Grand.Business.Catalog/Services/Products/RecentlyViewedProductsService.cs b/src/Business/Grand.Business.Catalog/Services/Products/RecentlyViewedProductsService.csindex cd27de2b6..6f9e61525 100644--- a/src/Business/Grand.Business.Catalog/Services/Products/RecentlyViewedProductsService.cs+++ b/src/Business/Grand.Business.Catalog/Services/Products/RecentlyViewedProductsService.cs@@ -3,8 +3,6 @@ using Grand.Infrastructure.Caching;using Grand.Infrastructure.Caching.Constants;using Grand.Domain.Catalog;using Grand.Domain.Data;-using MongoDB.Driver;-using MongoDB.Driver.Linq;using System;using System.Collections.Generic;using System.Linq;@@ -75,7 +73,7 @@ namespace Grand.Business.Catalog.Services.Productswhere p.CustomerId == customerIdorderby p.CreatedOnUtc descendingselect p.ProductId;- return await query.Take(number).ToListAsync();+ return await query.Take(number).ToListAsync2();});}diff --git a/src/Business/Grand.Business.Catalog/Services/Tax/TaxCategoryService.cs b/src/Business/Grand.Business.Catalog/Services/Tax/TaxCategoryService.csindex 43d4f543c..f86066c6e 100644--- a/src/Business/Grand.Business.Catalog/Services/Tax/TaxCategoryService.cs+++ b/src/Business/Grand.Business.Catalog/Services/Tax/TaxCategoryService.cs@@ -5,8 +5,6 @@ using Grand.Infrastructure.Extensions;using Grand.Domain.Data;using Grand.Domain.Tax;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;using System;using System.Collections.Generic;using System.Linq;@@ -60,7 +58,7 @@ namespace Grand.Business.Catalog.Services.Taxvar query = from tc in _taxCategoryRepository.Tableorderby tc.DisplayOrderselect tc;- return query.ToListAsync();+ return query.ToListAsync2();});}