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
KrzysztofPajak659171d651d3
diff --git a/src/Business/Grand.Business.Catalog/Events/Handlers/BrandDeletedEventHandler.cs b/src/Business/Grand.Business.Catalog/Events/Handlers/BrandDeletedEventHandler.csindex 8a6084949..d1cad208f 100644--- a/src/Business/Grand.Business.Catalog/Events/Handlers/BrandDeletedEventHandler.cs+++ b/src/Business/Grand.Business.Catalog/Events/Handlers/BrandDeletedEventHandler.cs@@ -2,7 +2,6 @@using Grand.Domain.Data;using Grand.Infrastructure.Events;using MediatR;-using MongoDB.Driver;using System.Threading;using System.Threading.Tasks;@@ -19,12 +18,8 @@ namespace Grand.Business.Catalog.Events.Handlerspublic async Task Handle(EntityDeleted<Brand> notification, CancellationToken cancellationToken){- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.BrandId, notification.Entity.Id);- var update = Builders<Product>.Update- .Set(x => x.BrandId, "");-- await _productRepository.Collection.UpdateManyAsync(filter, update);+ await _productRepository.UpdateManyAsync(x => x.BrandId == notification.Entity.Id,+ UpdateBuilder<Product>.Create().Set(x => x.BrandId, ""));}}}diff --git a/src/Business/Grand.Business.Catalog/Events/Handlers/CategoryDeletedEventHandler.cs b/src/Business/Grand.Business.Catalog/Events/Handlers/CategoryDeletedEventHandler.csindex 79ad4ca96..67ba8bef6 100644--- a/src/Business/Grand.Business.Catalog/Events/Handlers/CategoryDeletedEventHandler.cs+++ b/src/Business/Grand.Business.Catalog/Events/Handlers/CategoryDeletedEventHandler.cs@@ -1,14 +1,12 @@-using Grand.Domain.Data;-using Grand.Domain.Catalog;+using Grand.Domain.Catalog;+using Grand.Domain.Data;using Grand.Domain.Seo;+using Grand.Infrastructure.Caching;+using Grand.Infrastructure.Caching.Constants;using Grand.Infrastructure.Events;using MediatR;-using MongoDB.Driver;using System.Threading;using System.Threading.Tasks;-using MongoDB.Bson;-using Grand.Infrastructure.Caching.Constants;-using Grand.Infrastructure.Caching;namespace Grand.Business.Catalog.Events.Handlers{@@ -33,15 +31,10 @@ namespace Grand.Business.Catalog.Events.Handlerspublic async Task Handle(EntityDeleted<Category> notification, CancellationToken cancellationToken){//delete url- var filters = Builders<EntityUrl>.Filter;- var filter = filters.Eq(x => x.EntityId, notification.Entity.Id);- filter &= filters.Eq(x => x.EntityName, "Category");- await _entityUrlRepository.Collection.DeleteManyAsync(filter);+ await _entityUrlRepository.DeleteManyAsync(x => x.EntityId == notification.Entity.Id && x.EntityName == "Category");//delete on the product- var builder = Builders<Product>.Update;- var updatefilter = builder.PullFilter(x => x.ProductCategories, y => y.CategoryId == notification.Entity.Id);- await _productRepository.Collection.UpdateManyAsync(new BsonDocument(), updatefilter);+ await _productRepository.PullFilter(string.Empty, x => x.ProductCategories, z => z.CategoryId, notification.Entity.Id, true);//clear cacheawait _cacheBase.RemoveByPrefix(CacheKey.PRODUCTS_PATTERN_KEY);diff --git a/src/Business/Grand.Business.Catalog/Events/Handlers/CollectionDeletedEventHandler.cs b/src/Business/Grand.Business.Catalog/Events/Handlers/CollectionDeletedEventHandler.csindex dfecb78c0..1e191e61c 100644--- a/src/Business/Grand.Business.Catalog/Events/Handlers/CollectionDeletedEventHandler.cs+++ b/src/Business/Grand.Business.Catalog/Events/Handlers/CollectionDeletedEventHandler.cs@@ -1,14 +1,12 @@-using Grand.Domain.Data;-using Grand.Domain.Catalog;+using Grand.Domain.Catalog;+using Grand.Domain.Data;using Grand.Domain.Seo;+using Grand.Infrastructure.Caching;+using Grand.Infrastructure.Caching.Constants;using Grand.Infrastructure.Events;using MediatR;-using MongoDB.Driver;using System.Threading;using System.Threading.Tasks;-using Grand.Infrastructure.Caching;-using Grand.Infrastructure.Caching.Constants;-using MongoDB.Bson;namespace Grand.Business.Catalog.Events.Handlers{@@ -31,15 +29,10 @@ namespace Grand.Business.Catalog.Events.Handlerspublic async Task Handle(EntityDeleted<Collection> notification, CancellationToken cancellationToken){//delete url- var filters = Builders<EntityUrl>.Filter;- var filter = filters.Eq(x => x.EntityId, notification.Entity.Id);- filter = filter & filters.Eq(x => x.EntityName, "Collection");- await _entityUrlRepository.Collection.DeleteManyAsync(filter);+ await _entityUrlRepository.DeleteManyAsync(x => x.EntityId == notification.Entity.Id && x.EntityName == "Collection");//delete on the product- var builder = Builders<Product>.Update;- var updatefilter = builder.PullFilter(x => x.ProductCollections, y => y.CollectionId == notification.Entity.Id);- await _productRepository.Collection.UpdateManyAsync(new BsonDocument(), updatefilter);+ await _productRepository.PullFilter(string.Empty, x => x.ProductCollections, z => z.CollectionId, notification.Entity.Id, true);//clear cacheawait _cacheBase.RemoveByPrefix(CacheKey.PRODUCTS_PATTERN_KEY);diff --git a/src/Business/Grand.Business.Catalog/Events/Handlers/DeleteMeasureUnitOnProductEventHandler.cs b/src/Business/Grand.Business.Catalog/Events/Handlers/DeleteMeasureUnitOnProductEventHandler.csindex ae44ee054..f4fd3306b 100644--- a/src/Business/Grand.Business.Catalog/Events/Handlers/DeleteMeasureUnitOnProductEventHandler.cs+++ b/src/Business/Grand.Business.Catalog/Events/Handlers/DeleteMeasureUnitOnProductEventHandler.cs@@ -1,9 +1,8 @@-using Grand.Infrastructure.Events;-using Grand.Domain.Catalog;+using Grand.Domain.Catalog;using Grand.Domain.Data;using Grand.Domain.Directory;+using Grand.Infrastructure.Events;using MediatR;-using MongoDB.Driver;using System.Threading;using System.Threading.Tasks;@@ -20,12 +19,8 @@ namespace Grand.Business.Catalog.Events.Handlerspublic async Task Handle(EntityDeleted<MeasureUnit> notification, CancellationToken cancellationToken){- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.UnitId, notification.Entity.Id);- var update = Builders<Product>.Update- .Set(x => x.UnitId, "");-- await _repositoryProduct.Collection.UpdateManyAsync(filter, update);+ await _repositoryProduct.UpdateManyAsync(x => x.UnitId == notification.Entity.Id,+ UpdateBuilder<Product>.Create().Set(x => x.UnitId, ""));}}}diff --git a/src/Business/Grand.Business.Catalog/Events/Handlers/DeliveryDateDeletedEventHandler.cs b/src/Business/Grand.Business.Catalog/Events/Handlers/DeliveryDateDeletedEventHandler.csindex cf1139865..c80577fcf 100644--- a/src/Business/Grand.Business.Catalog/Events/Handlers/DeliveryDateDeletedEventHandler.cs+++ b/src/Business/Grand.Business.Catalog/Events/Handlers/DeliveryDateDeletedEventHandler.cs@@ -1,9 +1,8 @@-using Grand.Domain.Data;-using Grand.Domain.Catalog;+using Grand.Domain.Catalog;+using Grand.Domain.Data;using Grand.Domain.Shipping;using Grand.Infrastructure.Events;using MediatR;-using MongoDB.Driver;using System.Threading;using System.Threading.Tasks;@@ -20,12 +19,8 @@ namespace Grand.Business.Catalog.Events.Handlerspublic async Task Handle(EntityDeleted<DeliveryDate> notification, CancellationToken cancellationToken){- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.DeliveryDateId, notification.Entity.Id);- var update = Builders<Product>.Update- .Set(x => x.DeliveryDateId, "");-- await _productRepository.Collection.UpdateManyAsync(filter, update);+ await _productRepository.UpdateManyAsync(x => x.DeliveryDateId == notification.Entity.Id,+ UpdateBuilder<Product>.Create().Set(x => x.DeliveryDateId, ""));}}}diff --git a/src/Business/Grand.Business.Catalog/Events/Handlers/DiscountDeletedEventHandler.cs b/src/Business/Grand.Business.Catalog/Events/Handlers/DiscountDeletedEventHandler.csindex f160407bc..f670a2040 100644--- a/src/Business/Grand.Business.Catalog/Events/Handlers/DiscountDeletedEventHandler.cs+++ b/src/Business/Grand.Business.Catalog/Events/Handlers/DiscountDeletedEventHandler.cs@@ -1,21 +1,19 @@-using Grand.Infrastructure.Caching;+using Grand.Domain.Catalog;using Grand.Domain.Data;-using Grand.Domain.Catalog;using Grand.Domain.Discounts;using Grand.Domain.Vendors;+using Grand.Infrastructure.Caching;+using Grand.Infrastructure.Caching.Constants;using Grand.Infrastructure.Events;using MediatR;-using MongoDB.Bson;-using MongoDB.Driver;using System.Threading;using System.Threading.Tasks;-using Grand.Infrastructure.Caching.Constants;namespace Grand.Business.Catalog.Events.Handlers{public class DiscountDeletedEventHandler : INotificationHandler<EntityDeleted<Discount>>{-+#region Fieldsprivate readonly IRepository<Product> _productRepository;@@ -52,49 +50,45 @@ namespace Grand.Business.Catalog.Events.Handlers{var discount = notification.Entity;- var builder = Builders<BsonDocument>.Filter;if (discount.DiscountTypeId == DiscountType.AssignedToSkus){- var builderproduct = Builders<Product>.Update;- var updatefilter = builderproduct.Pull(x => x.AppliedDiscounts, discount.Id);- await _productRepository.Collection.UpdateManyAsync(new BsonDocument(), updatefilter);+ //delete on the product+ await _productRepository.Pull(string.Empty, x => x.AppliedDiscounts, discount.Id, true);+await _cacheBase.RemoveByPrefix(CacheKey.PRODUCTS_PATTERN_KEY);}if (discount.DiscountTypeId == DiscountType.AssignedToCategories){- var buildercategory = Builders<Category>.Update;- var updatefilter = buildercategory.Pull(x => x.AppliedDiscounts, discount.Id);- await _categoryRepository.Collection.UpdateManyAsync(new BsonDocument(), updatefilter);+ //delete on the category+ await _categoryRepository.Pull(string.Empty, x => x.AppliedDiscounts, discount.Id, true);+ //clear cacheawait _cacheBase.RemoveByPrefix(CacheKey.CATEGORIES_PATTERN_KEY);}if (discount.DiscountTypeId == DiscountType.AssignedToBrands){- var builderbrand = Builders<Brand>.Update;- var updatefilter = builderbrand.Pull(x => x.AppliedDiscounts, discount.Id);- await _brandRepository.Collection.UpdateManyAsync(new BsonDocument(), updatefilter);+ //delete on the brand+ await _brandRepository.Pull(string.Empty, x => x.AppliedDiscounts, discount.Id, true);+ //clear cacheawait _cacheBase.RemoveByPrefix(CacheKey.BRANDS_PATTERN_KEY);}if (discount.DiscountTypeId == DiscountType.AssignedToCollections){- var buildercollection = Builders<Collection>.Update;- var updatefilter = buildercollection.Pull(x => x.AppliedDiscounts, discount.Id);- await _collectionRepository.Collection.UpdateManyAsync(new BsonDocument(), updatefilter);+ //delete on the collection+ await _collectionRepository.Pull(string.Empty, x => x.AppliedDiscounts, discount.Id, true);+ //clear cacheawait _cacheBase.RemoveByPrefix(CacheKey.COLLECTIONS_PATTERN_KEY);}if (discount.DiscountTypeId == DiscountType.AssignedToVendors){- var buildervendor = Builders<Vendor>.Update;- var updatefilter = buildervendor.Pull(x => x.AppliedDiscounts, discount.Id);- await _vendorRepository.Collection.UpdateManyAsync(new BsonDocument(), updatefilter);+ //delete on the vendor+ await _vendorRepository.Pull(string.Empty, x => x.AppliedDiscounts, discount.Id, true);+ //clear cacheawait _cacheBase.RemoveByPrefix(CacheKey.PRODUCTS_PATTERN_KEY);}-- //remove coupon codes- var filtersCoupon = Builders<DiscountCoupon>.Filter;- var filterCrp = filtersCoupon.Eq(x => x.DiscountId, discount.Id);- await _discountCouponRepository.Collection.DeleteManyAsync(filterCrp);+ //remove coupon codes+ await _discountCouponRepository.DeleteManyAsync(x => x.DiscountId == discount.Id);}}}diff --git a/src/Business/Grand.Business.Catalog/Events/Handlers/ProductDeletedEventHandler.cs b/src/Business/Grand.Business.Catalog/Events/Handlers/ProductDeletedEventHandler.csindex 293115764..f9653bc8c 100644--- a/src/Business/Grand.Business.Catalog/Events/Handlers/ProductDeletedEventHandler.cs+++ b/src/Business/Grand.Business.Catalog/Events/Handlers/ProductDeletedEventHandler.cs@@ -5,8 +5,6 @@ using Grand.Domain.Customers;using Grand.Domain.Data;using Grand.Domain.Seo;using MediatR;-using MongoDB.Bson;-using MongoDB.Driver;using System.Linq;using System.Threading;using System.Threading.Tasks;@@ -49,41 +47,25 @@ namespace Grand.Business.Catalog.Events.Handlerspublic async Task Handle(EntityDeleted<Product> notification, CancellationToken cancellationToken){//delete related product- var builderRelated = Builders<Product>.Update;- var updatefilterRelated = builderRelated.PullFilter(x => x.RelatedProducts, y => y.ProductId2 == notification.Entity.Id);- await _productRepository.Collection.UpdateManyAsync(new BsonDocument(), updatefilterRelated);+ await _productRepository.PullFilter(string.Empty, x => x.RelatedProducts, z => z.ProductId2, notification.Entity.Id, true);//delete similar product- var builderSimilar = Builders<Product>.Update;- var updatefilterSimilar = builderSimilar.PullFilter(x => x.SimilarProducts, y => y.ProductId2 == notification.Entity.Id);- await _productRepository.Collection.UpdateManyAsync(new BsonDocument(), updatefilterSimilar);+ await _productRepository.PullFilter(string.Empty, x => x.SimilarProducts, z => z.ProductId2, notification.Entity.Id, true);//delete cross sales product- var builderCross = Builders<Product>.Update;- var updatefilterCross = builderCross.Pull(x => x.CrossSellProduct, notification.Entity.Id);- await _productRepository.Collection.UpdateManyAsync(new BsonDocument(), updatefilterCross);-+ await _productRepository.Pull(string.Empty, x => x.CrossSellProduct, notification.Entity.Id, true);//delete review- var filtersProductReview = Builders<ProductReview>.Filter;- var filterProdReview = filtersProductReview.Eq(x => x.ProductId, notification.Entity.Id);- await _productReviewRepository.Collection.DeleteManyAsync(filterProdReview);+ await _productReviewRepository.DeleteManyAsync(x=>x.ProductId == notification.Entity.Id);//delete from shopping cart- var builder = Builders<Customer>.Update;- var updatefilter = builder.PullFilter(x => x.ShoppingCartItems, y => y.ProductId == notification.Entity.Id);- await _customerRepository.Collection.UpdateManyAsync(new BsonDocument(), updatefilter);+ await _customerRepository.PullFilter(string.Empty, x => x.ShoppingCartItems, z => z.ProductId, notification.Entity.Id, true);//delete customer group product- var filtersCrp = Builders<CustomerGroupProduct>.Filter;- var filterCrp = filtersCrp.Eq(x => x.ProductId, notification.Entity.Id);- await _customerGroupProductRepository.Collection.DeleteManyAsync(filterCrp);+ await _customerGroupProductRepository.DeleteManyAsync(x => x.ProductId == notification.Entity.Id);//delete url- var filters = Builders<EntityUrl>.Filter;- var filter = filters.Eq(x => x.EntityId, notification.Entity.Id);- filter = filter & filters.Eq(x => x.EntityName, "Product");- await _entityUrlRepository.Collection.DeleteManyAsync(filter);+ await _entityUrlRepository.DeleteManyAsync(x => x.EntityId == notification.Entity.Id && x.EntityName == "Product");//delete product tagsvar existingProductTags = _productTagRepository.Table.Where(x => notification.Entity.ProductTags.ToList().Contains(x.Name)).ToList();diff --git a/src/Business/Grand.Business.Catalog/Events/Handlers/TaxCategoryDeletedEventHandler.cs b/src/Business/Grand.Business.Catalog/Events/Handlers/TaxCategoryDeletedEventHandler.csindex 96fa65d33..613bf10ba 100644--- a/src/Business/Grand.Business.Catalog/Events/Handlers/TaxCategoryDeletedEventHandler.cs+++ b/src/Business/Grand.Business.Catalog/Events/Handlers/TaxCategoryDeletedEventHandler.cs@@ -3,7 +3,6 @@ using Grand.Domain.Catalog;using Grand.Domain.Tax;using Grand.Infrastructure.Events;using MediatR;-using MongoDB.Driver;using System.Threading;using System.Threading.Tasks;@@ -20,12 +19,8 @@ namespace Grand.Business.Catalog.Events.Handlerspublic async Task Handle(EntityDeleted<TaxCategory> notification, CancellationToken cancellationToken){- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.TaxCategoryId, notification.Entity.Id);- var update = Builders<Product>.Update- .Set(x => x.TaxCategoryId, "");-- await _productRepository.Collection.UpdateManyAsync(filter, update);+ await _productRepository.UpdateManyAsync(x => x.TaxCategoryId == notification.Entity.Id,+ UpdateBuilder<Product>.Create().Set(x => x.TaxCategoryId, ""));}}}diff --git a/src/Business/Grand.Business.Catalog/Events/Handlers/UpdateProductOnCartEventHandler.cs b/src/Business/Grand.Business.Catalog/Events/Handlers/UpdateProductOnCartEventHandler.csindex 888b99a36..db69a7d72 100644--- a/src/Business/Grand.Business.Catalog/Events/Handlers/UpdateProductOnCartEventHandler.cs+++ b/src/Business/Grand.Business.Catalog/Events/Handlers/UpdateProductOnCartEventHandler.cs@@ -26,16 +26,13 @@ namespace Grand.Business.Catalog.Events.Handlers{foreach (var item in cs.ShoppingCartItems.Where(x => x.ProductId == notification.Product.Id)){- var updateCustomer = Builders<Customer>.Update- .Set(x => x.ShoppingCartItems.ElementAt(-1).AdditionalShippingChargeProduct, notification.Product.AdditionalShippingCharge)- .Set(x => x.ShoppingCartItems.ElementAt(-1).IsFreeShipping, notification.Product.IsFreeShipping)- .Set(x => x.ShoppingCartItems.ElementAt(-1).IsGiftVoucher, notification.Product.IsGiftVoucher)- .Set(x => x.ShoppingCartItems.ElementAt(-1).IsShipEnabled, notification.Product.IsShipEnabled)- .Set(x => x.ShoppingCartItems.ElementAt(-1).IsTaxExempt, notification.Product.IsTaxExempt);+ item.AdditionalShippingChargeProduct = notification.Product.AdditionalShippingCharge;+ item.IsFreeShipping = notification.Product.IsFreeShipping;+ item.IsGiftVoucher = notification.Product.IsGiftVoucher;+ item.IsShipEnabled = notification.Product.IsShipEnabled;+ item.IsTaxExempt = notification.Product.IsTaxExempt;- var _builderCustomer = Builders<Customer>.Filter;- var _filterCustomer = _builderCustomer.ElemMatch(x => x.ShoppingCartItems, y => y.Id == item.Id);- await _customerRepository.Collection.UpdateManyAsync(_filterCustomer, updateCustomer);+ await _customerRepository.UpdateToSet(cs.Id, x => x.ShoppingCartItems, z => z.Id, item.Id, item);}});diff --git a/src/Business/Grand.Business.Catalog/Events/Handlers/WarehouseDeletedEventHandler.cs b/src/Business/Grand.Business.Catalog/Events/Handlers/WarehouseDeletedEventHandler.csindex 8ef936752..45a371420 100644--- a/src/Business/Grand.Business.Catalog/Events/Handlers/WarehouseDeletedEventHandler.cs+++ b/src/Business/Grand.Business.Catalog/Events/Handlers/WarehouseDeletedEventHandler.cs@@ -3,8 +3,6 @@ using Grand.Domain.Catalog;using Grand.Domain.Shipping;using Grand.Infrastructure.Events;using MediatR;-using MongoDB.Bson;-using MongoDB.Driver;using System.Threading;using System.Threading.Tasks;@@ -21,17 +19,10 @@ namespace Grand.Business.Catalog.Events.Handlerspublic async Task Handle(EntityDeleted<Warehouse> notification, CancellationToken cancellationToken){- var builder = Builders<Product>.Update;- var updatefilter = builder.PullFilter(x => x.ProductWarehouseInventory, y => y.WarehouseId == notification.Entity.Id);+ await _productRepository.PullFilter(string.Empty, x => x.ProductWarehouseInventory, z => z.WarehouseId, notification.Entity.Id, true);- await _productRepository.Collection.UpdateManyAsync(new BsonDocument(), updatefilter);-- var builder2 = Builders<Product>.Filter;- var filter2 = builder2.Eq(x => x.WarehouseId, notification.Entity.Id);- var update2 = Builders<Product>.Update- .Set(x => x.WarehouseId, "");-- await _productRepository.Collection.UpdateManyAsync(filter2, update2);+ await _productRepository.UpdateManyAsync(x => x.WarehouseId == notification.Entity.Id,+ UpdateBuilder<Product>.Create().Set(x => x.WarehouseId, ""));}}diff --git a/src/Business/Grand.Business.Catalog/Interfaces/Products/IProductService.cs b/src/Business/Grand.Business.Catalog/Interfaces/Products/IProductService.csindex f252497d4..48e047408 100644--- a/src/Business/Grand.Business.Catalog/Interfaces/Products/IProductService.cs+++ b/src/Business/Grand.Business.Catalog/Interfaces/Products/IProductService.cs@@ -77,15 +77,15 @@ namespace Grand.Business.Catalog.Interfaces.Products/// <summary>/// Updates most view on the product/// </summary>- /// <param name="productId">ProductId</param>- Task UpdateMostView(string productId);+ /// <param name="product">Product</param>+ Task UpdateMostView(Product product);/// <summary>/// Updates best sellers on the product/// </summary>- /// <param name="productId">ProductId</param>+ /// <param name="product">Product</param>/// <param name="qty">Count</param>- Task UpdateSold(string productId, int qty);+ Task UpdateSold(Product product, int qty);/// <summary>/// Set product as unpublisheddiff --git a/src/Business/Grand.Business.Catalog/Services/Products/ProductReservationService.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductReservationService.csindex 8cd5ecc5d..2413b1911 100644--- a/src/Business/Grand.Business.Catalog/Services/Products/ProductReservationService.cs+++ b/src/Business/Grand.Business.Catalog/Services/Products/ProductReservationService.cs@@ -4,8 +4,6 @@ using Grand.Domain;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;@@ -161,8 +159,8 @@ namespace Grand.Business.Catalog.Services.Products{if (!string.IsNullOrEmpty(orderId)){- var update = new UpdateDefinitionBuilder<ProductReservation>().Set(x => x.OrderId, "");- await _productReservationRepository.Collection.UpdateManyAsync(x => x.OrderId == orderId, update);+ await _productReservationRepository.UpdateManyAsync(x => x.OrderId == orderId,+ UpdateBuilder<ProductReservation>.Create().Set(x => x.OrderId, ""));}}@@ -182,7 +180,7 @@ namespace Grand.Business.Catalog.Services.Products/// <returns>List<CustomerReservationsHelper></returns>public virtual async Task<IList<CustomerReservationsHelper>> GetCustomerReservationsHelpers(string customerId){- return await _customerReservationsHelperRepository.Table.Where(x => x.CustomerId == customerId).ToListAsync();+ return await _customerReservationsHelperRepository.Table.Where(x => x.CustomerId == customerId).ToListAsync2();}/// <summary>@@ -192,7 +190,7 @@ namespace Grand.Business.Catalog.Services.Products/// <returns>List<CustomerReservationsHelper></returns>public virtual async Task<IList<CustomerReservationsHelper>> GetCustomerReservationsHelperBySciId(string sciId){- return await _customerReservationsHelperRepository.Table.Where(x => x.ShoppingCartItemId == sciId).ToListAsync();+ return await _customerReservationsHelperRepository.Table.Where(x => x.ShoppingCartItemId == sciId).ToListAsync2();}}}diff --git a/src/Business/Grand.Business.Catalog/Services/Products/ProductReviewService.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductReviewService.csindex 84580a8d8..042ee44fa 100644--- a/src/Business/Grand.Business.Catalog/Services/Products/ProductReviewService.cs+++ b/src/Business/Grand.Business.Catalog/Services/Products/ProductReviewService.cs@@ -90,9 +90,7 @@ namespace Grand.Business.Catalog.Services.Productsif (productreview == null)throw new ArgumentNullException(nameof(productreview));- var builder = Builders<ProductReview>.Filter;- var filter = builder.Eq(x => x.Id, productreview.Id);- var update = Builders<ProductReview>.Update+ var update = UpdateBuilder<ProductReview>.Create().Set(x => x.Title, productreview.Title).Set(x => x.ReviewText, productreview.ReviewText).Set(x => x.ReplyText, productreview.ReplyText)@@ -103,7 +101,7 @@ namespace Grand.Business.Catalog.Services.Products.Set(x => x.HelpfulYesTotal, productreview.HelpfulYesTotal).Set(x => x.ProductReviewHelpfulnessEntries, productreview.ProductReviewHelpfulnessEntries);- await _productReviewRepository.Collection.UpdateManyAsync(filter, update);+ await _productReviewRepository.UpdateOneAsync(x => x.Id == productreview.Id, update);//event notificationawait _mediator.EntityUpdated(productreview);diff --git a/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductService.csindex ac73d2a1d..73e6613b0 100644--- a/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs+++ b/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs@@ -13,9 +13,6 @@ using Grand.Infrastructure.Caching;using Grand.Infrastructure.Caching.Constants;using Grand.Infrastructure.Extensions;using MediatR;-using MongoDB.Bson;-using MongoDB.Driver;-using MongoDB.Driver.Linq;using System;using System.Collections.Generic;using System.Linq;@@ -69,15 +66,10 @@ namespace Grand.Business.Catalog.Services.Products/// <returns>Products</returns>public virtual async Task<IList<string>> GetAllProductsDisplayedOnHomePage(){- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Published, true);- filter &= builder.Eq(x => x.ShowOnHomePage, true);- filter &= builder.Eq(x => x.VisibleIndividually, true);- var query = _productRepository.Collection.Find(filter).- SortBy(x => x.DisplayOrder).ThenBy(x => x.Name).- Project(x => x.Id);+ var query = _productRepository.Table.Where(x=>x.Published && x.ShowOnHomePage && x.VisibleIndividually)+ .OrderBy(x => x.DisplayOrder).ThenBy(x => x.Name).Select(x => x.Id);- var products = await query.ToListAsync();+ var products = await query.ToListAsync2();return products;}@@ -88,15 +80,11 @@ namespace Grand.Business.Catalog.Services.Products/// <returns>Products</returns>public virtual async Task<IList<string>> GetAllProductsDisplayedOnBestSeller(){- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Published, true);- filter &= builder.Eq(x => x.BestSeller, true);- filter &= builder.Eq(x => x.VisibleIndividually, true);- var query = _productRepository.Collection.Find(filter).- SortBy(x => x.DisplayOrder).ThenBy(x => x.Name).- Project(x => x.Id);+ var query = _productRepository.Table.Where(x=>x.Published && x.BestSeller && x.VisibleIndividually)+ .OrderBy(x => x.DisplayOrder).ThenBy(x => x.Name)+ .Select(x => x.Id);- var products = await query.ToListAsync();+ var products = await query.ToListAsync2();return products;}@@ -201,9 +189,7 @@ namespace Grand.Business.Catalog.Services.Productsvar oldProduct = await _productRepository.GetByIdAsync(product.Id);//update- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, product.Id);- var update = Builders<Product>.Update+ var update = UpdateBuilder<Product>.Create().Set(x => x.AdditionalShippingCharge, product.AdditionalShippingCharge).Set(x => x.AdminComment, product.AdminComment).Set(x => x.AllowOutOfStockSubscriptions, product.AllowOutOfStockSubscriptions)@@ -269,7 +255,7 @@ namespace Grand.Business.Catalog.Services.Products.Set(x => x.MetaTitle, product.MetaTitle).Set(x => x.MinEnteredPrice, product.MinEnteredPrice).Set(x => x.MinStockQuantity, product.MinStockQuantity)- .Set(x => x.LowStock, ((product.MinStockQuantity > 0 && product.MinStockQuantity >= product.StockQuantity-product.ReservedQuantity) || product.StockQuantity-product.ReservedQuantity <= 0))+ .Set(x => x.LowStock, ((product.MinStockQuantity > 0 && product.MinStockQuantity >= product.StockQuantity - product.ReservedQuantity) || product.StockQuantity - product.ReservedQuantity <= 0)).Set(x => x.Name, product.Name).Set(x => x.NotApprovedRatingSum, product.NotApprovedRatingSum).Set(x => x.NotApprovedTotalReviews, product.NotApprovedTotalReviews)@@ -316,9 +302,9 @@ namespace Grand.Business.Catalog.Services.Products.Set(x => x.Weight, product.Weight).Set(x => x.Width, product.Width).Set(x => x.UserFields, product.UserFields)- .CurrentDate("UpdatedOnUtc");+ .Set(x=>x.UpdatedOnUtc, DateTime.UtcNow);- await _productRepository.Collection.UpdateOneAsync(filter, update);+ await _productRepository.UpdateOneAsync(x => x.Id == product.Id, update);if (oldProduct.AdditionalShippingCharge != product.AdditionalShippingCharge ||oldProduct.IsFreeShipping != product.IsFreeShipping ||@@ -369,25 +355,24 @@ namespace Grand.Business.Catalog.Services.Productsawait _mediator.EntityDeleted(product);}- public virtual async Task UpdateMostView(string productId)+ public virtual async Task UpdateMostView(Product product){- var update = new UpdateDefinitionBuilder<Product>().Inc(x => x.Viewed, 1);- await _productRepository.Collection.UpdateManyAsync(x => x.Id == productId, update);+ await _productRepository.UpdateField(product.Id, x => x.Viewed, product.Viewed = +1);}- public virtual async Task UpdateSold(string productId, int qty)+ public virtual async Task UpdateSold(Product product, int qty){- var update = new UpdateDefinitionBuilder<Product>().Inc(x => x.Sold, qty);- await _productRepository.Collection.UpdateManyAsync(x => x.Id == productId, update);+ await _productRepository.UpdateField(product.Id, x => x.Sold, product.Sold = qty);}public virtual async Task UnpublishProduct(Product product){- var filter = Builders<Product>.Filter.Eq("Id", product.Id);- var update = Builders<Product>.Update+ var update = UpdateBuilder<Product>.Create().Set(x => x.Published, false)- .CurrentDate("UpdatedOnUtc");- await _productRepository.Collection.UpdateOneAsync(filter, update);+ .Set(x=>x.UpdatedOnUtc, DateTime.UtcNow);++ await _productRepository.UpdateOneAsync(x=>x.Id == product.Id, update);+await _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, product.Id));//event@@ -412,29 +397,35 @@ namespace Grand.Business.Catalog.Services.Productsif (categoryIds != null && categoryIds.Contains(""))categoryIds.Remove("");- var builder = Builders<Product>.Filter;- var filter = builder.Where(p => p.Published && p.VisibleIndividually);+ var query = from p in _productRepository.Table+ select p;++ query = query.Where(p => p.Published && p.VisibleIndividually);+////category filteringif (categoryIds != null && categoryIds.Any()){- filter &= builder.Where(p => p.ProductCategories.Any(x => categoryIds.Contains(x.CategoryId)));+ query = query.Where(p => p.ProductCategories.Any(x => categoryIds.Contains(x.CategoryId)));}if (!ignoreAcl){//ACL (access control list)var allowedCustomerGroupsIds = customer.GetCustomerGroupIds();- filter &= (builder.AnyIn(x => x.CustomerGroups, allowedCustomerGroupsIds) | builder.Where(x => !x.LimitedToGroups));+ query = from p in query+ where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))+ select p;}if (!string.IsNullOrEmpty(storeId) && !ignoreStore){- //Store acl- var currentStoreId = new List<string> { storeId };- filter &= (builder.AnyIn(x => x.Stores, currentStoreId) | builder.Where(x => !x.LimitedToStores));+ //Limited to stores rules+ query = from p in query+ where !p.LimitedToStores || p.Stores.Contains(storeId)+ select p;}- return Convert.ToInt32(_productRepository.Collection.Find(filter).CountDocuments());+ return Convert.ToInt32(query.Count());}@@ -499,8 +490,7 @@ namespace Grand.Business.Catalog.Services.Productsbool? overridePublished = null){- var model = await _mediator.Send(new GetSearchProductsQuery()- {+ var model = await _mediator.Send(new GetSearchProductsQuery() {Customer = _workContext.CurrentCustomer,LoadFilterableSpecificationAttributeOptionIds = loadFilterableSpecificationAttributeOptionIds,PageIndex = pageIndex,@@ -561,31 +551,31 @@ namespace Grand.Business.Catalog.Services.Productsstring storeId = "", string vendorId = "", bool showHidden = false){- var builder = Builders<Product>.Filter;- var filter = FilterDefinition<Product>.Empty;+ var query = from p in _productRepository.Table+ select p;- filter = filter & builder.Where(p => p.ParentGroupedProductId == parentGroupedProductId);+ query = query.Where(p => p.ParentGroupedProductId == parentGroupedProductId);if (!showHidden){- filter = filter & builder.Where(p => p.Published);+ query = query.Where(p => p.Published);}if (!showHidden){var nowUtc = DateTime.UtcNow;//available dates- filter = filter & builder.Where(p =>+ query = query.Where(p =>(p.AvailableStartDateTimeUtc == null || p.AvailableStartDateTimeUtc < nowUtc) &&(p.AvailableEndDateTimeUtc == null || p.AvailableEndDateTimeUtc > nowUtc));}//vendor filtering- if (!String.IsNullOrEmpty(vendorId))+ if (!string.IsNullOrEmpty(vendorId)){- filter = filter & builder.Where(p => p.VendorId == vendorId);+ query = query.Where(p => p.VendorId == vendorId);}- var products = await _productRepository.Collection.Find(filter).SortBy(x => x.DisplayOrder).ToListAsync();+ var products = await query.OrderBy(x => x.DisplayOrder).ToListAsync2();//ACL mappingif (!showHidden)@@ -612,8 +602,7 @@ namespace Grand.Business.Catalog.Services.Productsreturn null;sku = sku.Trim();- var filter = Builders<Product>.Filter.Eq(x => x.Sku, sku);- return await _productRepository.Collection.Find(filter).FirstOrDefaultAsync();+ return await _productRepository.Table.Where(x=>x.Sku == sku).FirstOrDefaultAsync2();}public virtual async Task UpdateAssociatedProduct(Product product)@@ -621,13 +610,11 @@ namespace Grand.Business.Catalog.Services.Productsif (product == null)throw new ArgumentNullException(nameof(product));- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, product.Id);- var update = Builders<Product>.Update+ var update = UpdateBuilder<Product>.Create().Set(x => x.DisplayOrder, product.DisplayOrder).Set(x => x.ParentGroupedProductId, product.ParentGroupedProductId);- await _productRepository.Collection.UpdateManyAsync(filter, update);+ await _productRepository.UpdateManyAsync(x => x.Id == product.Id, update);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, product.Id));@@ -652,9 +639,7 @@ namespace Grand.Business.Catalog.Services.Productsif (relatedProduct == null)throw new ArgumentNullException(nameof(relatedProduct));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.AddToSet(p => p.RelatedProducts, relatedProduct);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", productId), update);+ await _productRepository.AddToSet(productId, x => x.RelatedProducts, relatedProduct);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productId));@@ -672,9 +657,7 @@ namespace Grand.Business.Catalog.Services.Productsif (relatedProduct == null)throw new ArgumentNullException(nameof(relatedProduct));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.Pull(p => p.RelatedProducts, relatedProduct);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", productId), update);+ await _productRepository.PullFilter(productId, x => x.RelatedProducts, z => z.Id, relatedProduct.Id);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productId));@@ -693,13 +676,7 @@ namespace Grand.Business.Catalog.Services.Productsif (relatedProduct == null)throw new ArgumentNullException(nameof(relatedProduct));- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, productId);- filter = filter & builder.ElemMatch(x => x.RelatedProducts, y => y.Id == relatedProduct.Id);- var update = Builders<Product>.Update- .Set(x => x.RelatedProducts.ElementAt(-1).DisplayOrder, relatedProduct.DisplayOrder);-- await _productRepository.Collection.UpdateManyAsync(filter, update);+ await _productRepository.UpdateToSet(productId, x => x.RelatedProducts, z => z.Id, relatedProduct.Id, relatedProduct);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productId));@@ -717,9 +694,7 @@ namespace Grand.Business.Catalog.Services.Productsif (similarProduct == null)throw new ArgumentNullException(nameof(similarProduct));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.AddToSet(p => p.SimilarProducts, similarProduct);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", similarProduct.ProductId1), update);+ await _productRepository.AddToSet(similarProduct.ProductId1, x => x.SimilarProducts, similarProduct);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, similarProduct.ProductId1));@@ -737,13 +712,7 @@ namespace Grand.Business.Catalog.Services.Productsif (similarProduct == null)throw new ArgumentNullException(nameof(similarProduct));- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, similarProduct.ProductId1);- filter = filter & builder.ElemMatch(x => x.SimilarProducts, y => y.Id == similarProduct.Id);- var update = Builders<Product>.Update- .Set(x => x.SimilarProducts.ElementAt(-1).DisplayOrder, similarProduct.DisplayOrder);-- await _productRepository.Collection.UpdateManyAsync(filter, update);+ await _productRepository.UpdateToSet(similarProduct.ProductId1, x => x.SimilarProducts, z => z.Id, similarProduct.Id, similarProduct);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, similarProduct.ProductId1));@@ -760,9 +729,7 @@ namespace Grand.Business.Catalog.Services.Productsif (similarProduct == null)throw new ArgumentNullException(nameof(similarProduct));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.Pull(p => p.SimilarProducts, similarProduct);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", similarProduct.ProductId1), update);+ await _productRepository.PullFilter(similarProduct.ProductId1, x => x.SimilarProducts, z => z.Id, similarProduct.Id);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, similarProduct.ProductId1));@@ -785,9 +752,7 @@ namespace Grand.Business.Catalog.Services.Productsif (bundleProduct == null)throw new ArgumentNullException(nameof(bundleProduct));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.AddToSet(p => p.BundleProducts, bundleProduct);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", productBundleId), update);+ await _productRepository.AddToSet(productBundleId, x => x.BundleProducts, bundleProduct);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productBundleId));@@ -807,14 +772,7 @@ namespace Grand.Business.Catalog.Services.Productsif (bundleProduct == null)throw new ArgumentNullException(nameof(bundleProduct));- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, productBundleId);- filter = filter & builder.ElemMatch(x => x.BundleProducts, y => y.Id == bundleProduct.Id);- var update = Builders<Product>.Update- .Set(x => x.BundleProducts.ElementAt(-1).Quantity, bundleProduct.Quantity)- .Set(x => x.BundleProducts.ElementAt(-1).DisplayOrder, bundleProduct.DisplayOrder);-- await _productRepository.Collection.UpdateManyAsync(filter, update);+ await _productRepository.UpdateToSet(productBundleId, x => x.BundleProducts, z => z.Id, bundleProduct.Id, bundleProduct);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productBundleId));@@ -833,9 +791,7 @@ namespace Grand.Business.Catalog.Services.Productsif (bundleProduct == null)throw new ArgumentNullException(nameof(bundleProduct));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.Pull(p => p.BundleProducts, bundleProduct);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", productBundleId), update);+ await _productRepository.PullFilter(productBundleId, x => x.BundleProducts, z => z.Id, bundleProduct.Id);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productBundleId));@@ -857,9 +813,7 @@ namespace Grand.Business.Catalog.Services.Productsif (crossSellProduct == null)throw new ArgumentNullException(nameof(crossSellProduct));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.AddToSet(p => p.CrossSellProduct, crossSellProduct.ProductId2);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", crossSellProduct.ProductId1), update);+ await _productRepository.AddToSet(crossSellProduct.ProductId1, x => x.CrossSellProduct, crossSellProduct.ProductId2);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, crossSellProduct.ProductId1));@@ -877,9 +831,7 @@ namespace Grand.Business.Catalog.Services.Productsif (crossSellProduct == null)throw new ArgumentNullException(nameof(crossSellProduct));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.Pull(p => p.CrossSellProduct, crossSellProduct.ProductId2);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", crossSellProduct.ProductId1), update);+ await _productRepository.Pull(crossSellProduct.ProductId1, x => x.CrossSellProduct, crossSellProduct.ProductId2);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, crossSellProduct.ProductId1));@@ -958,10 +910,8 @@ namespace Grand.Business.Catalog.Services.Productsif (tierPrice == null)throw new ArgumentNullException(nameof(tierPrice));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.AddToSet(p => p.TierPrices, tierPrice);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", productId), update);-+ await _productRepository.AddToSet(productId, x => x.TierPrices, tierPrice);+//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productId));@@ -979,20 +929,7 @@ namespace Grand.Business.Catalog.Services.Productsif (tierPrice == null)throw new ArgumentNullException(nameof(tierPrice));- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, productId);- filter = filter & builder.Where(x => x.TierPrices.Any(y => y.Id == tierPrice.Id));-- var update = Builders<Product>.Update- .Set(x => x.TierPrices.ElementAt(-1).Price, tierPrice.Price)- .Set(x => x.TierPrices.ElementAt(-1).Quantity, tierPrice.Quantity)- .Set(x => x.TierPrices.ElementAt(-1).StoreId, tierPrice.StoreId)- .Set(x => x.TierPrices.ElementAt(-1).CustomerGroupId, tierPrice.CustomerGroupId)- .Set(x => x.TierPrices.ElementAt(-1).CurrencyCode, tierPrice.CurrencyCode)- .Set(x => x.TierPrices.ElementAt(-1).StartDateTimeUtc, tierPrice.StartDateTimeUtc)- .Set(x => x.TierPrices.ElementAt(-1).EndDateTimeUtc, tierPrice.EndDateTimeUtc);-- await _productRepository.Collection.UpdateManyAsync(filter, update);+ await _productRepository.UpdateToSet(productId, x => x.TierPrices, z => z.Id, tierPrice.Id, tierPrice);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productId));@@ -1010,9 +947,7 @@ namespace Grand.Business.Catalog.Services.Productsif (tierPrice == null)throw new ArgumentNullException(nameof(tierPrice));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.Pull(p => p.TierPrices, tierPrice);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", productId), update);+ await _productRepository.PullFilter(productId, x => x.TierPrices, x=>x.Id, tierPrice.Id);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productId));@@ -1034,9 +969,7 @@ namespace Grand.Business.Catalog.Services.Productsif (productPrice == null)throw new ArgumentNullException(nameof(productPrice));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.AddToSet(p => p.ProductPrices, productPrice);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", productPrice.ProductId), update);+ await _productRepository.AddToSet(productPrice.ProductId, x => x.ProductPrices, productPrice);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productPrice.ProductId));@@ -1054,15 +987,7 @@ namespace Grand.Business.Catalog.Services.Productsif (productPrice == null)throw new ArgumentNullException(nameof(productPrice));- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, productPrice.ProductId);- filter &= builder.Where(x => x.ProductPrices.Any(y => y.Id == productPrice.Id));-- var update = Builders<Product>.Update- .Set(x => x.ProductPrices.ElementAt(-1).Price, productPrice.Price)- .Set(x => x.ProductPrices.ElementAt(-1).CurrencyCode, productPrice.CurrencyCode);-- await _productRepository.Collection.UpdateManyAsync(filter, update);+ await _productRepository.UpdateToSet(productPrice.ProductId, x => x.ProductPrices, z => z.Id, productPrice.Id, productPrice);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productPrice.ProductId));@@ -1080,9 +1005,7 @@ namespace Grand.Business.Catalog.Services.Productsif (productPrice == null)throw new ArgumentNullException(nameof(productPrice));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.Pull(p => p.ProductPrices, productPrice);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", productPrice.ProductId), update);+ await _productRepository.PullFilter(productPrice.Id, x => x.ProductPrices, x => x.Id, productPrice.Id);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productPrice.ProductId));@@ -1104,9 +1027,7 @@ namespace Grand.Business.Catalog.Services.Productsif (productPicture == null)throw new ArgumentNullException(nameof(productPicture));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.AddToSet(p => p.ProductPictures, productPicture);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", productId), update);+ await _productRepository.AddToSet(productId, x => x.ProductPictures, productPicture);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productId));@@ -1125,13 +1046,7 @@ namespace Grand.Business.Catalog.Services.Productsif (productPicture == null)throw new ArgumentNullException(nameof(productPicture));- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, productId);- filter &= builder.ElemMatch(x => x.ProductPictures, y => y.Id == productPicture.Id);- var update = Builders<Product>.Update- .Set(x => x.ProductPictures.ElementAt(-1).DisplayOrder, productPicture.DisplayOrder);-- await _productRepository.Collection.UpdateManyAsync(filter, update);+ await _productRepository.UpdateToSet(productId, x => x.ProductPictures, z => z.Id, productPicture.Id, productPicture);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productId));@@ -1149,9 +1064,7 @@ namespace Grand.Business.Catalog.Services.Productsif (productPicture == null)throw new ArgumentNullException(nameof(productPicture));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.Pull(p => p.ProductPictures, productPicture);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", productId), update);+ await _productRepository.PullFilter(productId, x => x.ProductPictures, x => x.Id, productPicture.Id);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productId));@@ -1173,9 +1086,7 @@ namespace Grand.Business.Catalog.Services.Productsif (pwi == null)throw new ArgumentNullException(nameof(pwi));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.AddToSet(p => p.ProductWarehouseInventory, pwi);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", productId), update);+ await _productRepository.AddToSet(productId, x => x.ProductWarehouseInventory, pwi);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productId));@@ -1194,14 +1105,7 @@ namespace Grand.Business.Catalog.Services.Productsif (pwi == null)throw new ArgumentNullException(nameof(pwi));- var builder = Builders<Product>.Filter;- var filter = builder.Eq(x => x.Id, productId);- filter = filter & builder.ElemMatch(x => x.ProductWarehouseInventory, y => y.Id == pwi.Id);- var update = Builders<Product>.Update- .Set(x => x.ProductWarehouseInventory.ElementAt(-1).StockQuantity, pwi.StockQuantity)- .Set(x => x.ProductWarehouseInventory.ElementAt(-1).ReservedQuantity, pwi.ReservedQuantity);-- await _productRepository.Collection.UpdateManyAsync(filter, update);+ await _productRepository.UpdateToSet(productId, x => x.ProductWarehouseInventory, z => z.Id, pwi.Id, pwi);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productId));@@ -1218,9 +1122,7 @@ namespace Grand.Business.Catalog.Services.Productsif (pwi == null)throw new ArgumentNullException(nameof(pwi));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.Pull(p => p.ProductWarehouseInventory, pwi);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", productId), update);+ await _productRepository.PullFilter(productId, x => x.ProductWarehouseInventory, x => x.Id, pwi.Id);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productId));@@ -1235,9 +1137,7 @@ namespace Grand.Business.Catalog.Services.Productsif (string.IsNullOrEmpty(discountId))throw new ArgumentNullException(nameof(discountId));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.Pull(p => p.AppliedDiscounts, discountId);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", productId), update);+ await _productRepository.Pull(productId, x => x.AppliedDiscounts, discountId);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productId));@@ -1248,10 +1148,7 @@ namespace Grand.Business.Catalog.Services.Productsif (string.IsNullOrEmpty(discountId))throw new ArgumentNullException(nameof(discountId));- var updatebuilder = Builders<Product>.Update;- var update = updatebuilder.AddToSet(p => p.AppliedDiscounts, discountId);- await _productRepository.Collection.UpdateOneAsync(new BsonDocument("_id", productId), update);-+ await _productRepository.AddToSet(productId, x => x.AppliedDiscounts, discountId);//cacheawait _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productId));}diff --git a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.csindex 4f1ab9800..f2686bb16 100644--- a/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs+++ b/src/Business/Grand.Business.Checkout/Commands/Handlers/Orders/PlaceOrderCommandHandler.cs@@ -1069,7 +1069,7 @@ namespace Grand.Business.Checkout.Commands.Handlers.Ordersawait _inventoryManageService.AdjustReserved(product, -sc.Quantity, sc.Attributes, orderItem.WarehouseId);//update sold- await _productService.UpdateSold(sc.ProductId, sc.Quantity);+ await _productService.UpdateSold(product, sc.Quantity);}//insert order