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
DatabaseContext - add new methods: CreateTable/CreateIndex
KrzysztofPajak658dd5b9ce02
diff --git a/src/Business/Grand.Business.System/Services/Installation/InstallationService.cs b/src/Business/Grand.Business.System/Services/Installation/InstallationService.csindex fbabd5d2d..f41be6e87 100644--- a/src/Business/Grand.Business.System/Services/Installation/InstallationService.cs+++ b/src/Business/Grand.Business.System/Services/Installation/InstallationService.cs@@ -33,7 +33,6 @@ using Grand.Infrastructure.TypeSearchers;using Grand.SharedKernel;using Microsoft.AspNetCore.Hosting;using Microsoft.Extensions.DependencyInjection;-using MongoDB.Driver;using System;using System.IO;using System.Linq;@@ -45,87 +44,87 @@ namespace Grand.Business.System.Services.Installation{#region Fields- private readonly MongoRepository<GrandNodeVersion> _versionRepository;- private readonly MongoRepository<AdminSiteMap> _adminRepository;- private readonly MongoRepository<Bid> _bidRepository;- private readonly MongoRepository<Affiliate> _affiliateRepository;- private readonly MongoRepository<CampaignHistory> _campaignHistoryRepository;- private readonly MongoRepository<Order> _orderRepository;- private readonly MongoRepository<OrderNote> _orderNoteRepository;- private readonly MongoRepository<MerchandiseReturn> _merchandiseReturnRepository;- private readonly MongoRepository<MerchandiseReturnNote> _merchandiseReturnNoteRepository;- private readonly MongoRepository<Store> _storeRepository;- private readonly MongoRepository<MeasureDimension> _measureDimensionRepository;- private readonly MongoRepository<MeasureWeight> _measureWeightRepository;- private readonly MongoRepository<MeasureUnit> _measureUnitRepository;- private readonly MongoRepository<TaxCategory> _taxCategoryRepository;- private readonly MongoRepository<Language> _languageRepository;- private readonly MongoRepository<TranslationResource> _lsrRepository;- private readonly MongoRepository<Log> _logRepository;- private readonly MongoRepository<Currency> _currencyRepository;- private readonly MongoRepository<Customer> _customerRepository;- private readonly MongoRepository<CustomerGroup> _customerGroupRepository;- private readonly MongoRepository<CustomerGroupProduct> _customerGroupProductRepository;- private readonly MongoRepository<CustomerProduct> _customerProductRepository;- private readonly MongoRepository<CustomerProductPrice> _customerProductPriceRepository;- private readonly MongoRepository<CustomerTagProduct> _customerTagProductRepository;- private readonly MongoRepository<CustomerHistoryPassword> _customerHistoryPasswordRepository;- private readonly MongoRepository<CustomerNote> _customerNoteRepository;- private readonly MongoRepository<UserApi> _userapiRepository;- private readonly MongoRepository<SpecificationAttribute> _specificationAttributeRepository;- private readonly MongoRepository<CheckoutAttribute> _checkoutAttributeRepository;- private readonly MongoRepository<ProductAttribute> _productAttributeRepository;- private readonly MongoRepository<Category> _categoryRepository;- private readonly MongoRepository<Brand> _brandRepository;- private readonly MongoRepository<Vendor> _vendorRepository;- private readonly MongoRepository<Collection> _collectionRepository;- private readonly MongoRepository<Product> _productRepository;- private readonly MongoRepository<ProductReservation> _productReservationRepository;- private readonly MongoRepository<ProductAlsoPurchased> _productalsopurchasedRepository;- private readonly MongoRepository<EntityUrl> _entityUrlRepository;- private readonly MongoRepository<EmailAccount> _emailAccountRepository;- private readonly MongoRepository<MessageTemplate> _messageTemplateRepository;- private readonly MongoRepository<Country> _countryRepository;- private readonly MongoRepository<Discount> _discountRepository;- private readonly MongoRepository<DiscountCoupon> _discountCouponRepository;- private readonly MongoRepository<DiscountUsageHistory> _discountusageRepository;- private readonly MongoRepository<BlogPost> _blogPostRepository;- private readonly MongoRepository<Page> _pageRepository;- private readonly MongoRepository<NewsItem> _newsItemRepository;- private readonly MongoRepository<NewsLetterSubscription> _newslettersubscriptionRepository;- private readonly MongoRepository<ShippingMethod> _shippingMethodRepository;- private readonly MongoRepository<DeliveryDate> _deliveryDateRepository;- private readonly MongoRepository<ActivityLogType> _activityLogTypeRepository;- private readonly MongoRepository<ProductTag> _productTagRepository;- private readonly MongoRepository<ProductReview> _productReviewRepository;- private readonly MongoRepository<ProductLayout> _productLayoutRepository;- private readonly MongoRepository<CategoryLayout> _categoryLayoutRepository;- private readonly MongoRepository<BrandLayout> _brandLayoutRepository;- private readonly MongoRepository<CollectionLayout> _collectionLayoutRepository;- private readonly MongoRepository<PageLayout> _pageLayoutRepository;- private readonly MongoRepository<ScheduleTask> _scheduleTaskRepository;- private readonly MongoRepository<LoyaltyPointsHistory> _loyaltypointshistoryRepository;- private readonly MongoRepository<SearchTerm> _searchtermRepository;- private readonly MongoRepository<Setting> _settingRepository;- private readonly MongoRepository<Shipment> _shipmentRepository;- private readonly MongoRepository<Warehouse> _warehouseRepository;- private readonly MongoRepository<PickupPoint> _pickupPointsRepository;- private readonly MongoRepository<Permission> _permissionRepository;- private readonly MongoRepository<PermissionAction> _permissionAction;- private readonly MongoRepository<ExternalAuthentication> _externalAuthenticationRepository;- private readonly MongoRepository<MerchandiseReturnReason> _merchandiseReturnReasonRepository;- private readonly MongoRepository<MerchandiseReturnAction> _merchandiseReturnActionRepository;- private readonly MongoRepository<ContactUs> _contactUsRepository;- private readonly MongoRepository<CustomerAction> _customerAction;- private readonly MongoRepository<CustomerActionType> _customerActionType;- private readonly MongoRepository<CustomerActionHistory> _customerActionHistory;- private readonly MongoRepository<PopupArchive> _popupArchive;- private readonly MongoRepository<CustomerReminderHistory> _customerReminderHistoryRepository;- private readonly MongoRepository<RecentlyViewedProduct> _recentlyViewedProductRepository;- private readonly MongoRepository<KnowledgebaseArticle> _knowledgebaseArticleRepository;- private readonly MongoRepository<KnowledgebaseCategory> _knowledgebaseCategoryRepository;- private readonly MongoRepository<OrderTag> _orderTagRepository;- private readonly MongoRepository<OrderStatus> _orderStatusRepository;+ private readonly IRepository<GrandNodeVersion> _versionRepository;+ private readonly IRepository<AdminSiteMap> _adminRepository;+ private readonly IRepository<Bid> _bidRepository;+ private readonly IRepository<Affiliate> _affiliateRepository;+ private readonly IRepository<CampaignHistory> _campaignHistoryRepository;+ private readonly IRepository<Order> _orderRepository;+ private readonly IRepository<OrderNote> _orderNoteRepository;+ private readonly IRepository<MerchandiseReturn> _merchandiseReturnRepository;+ private readonly IRepository<MerchandiseReturnNote> _merchandiseReturnNoteRepository;+ private readonly IRepository<Store> _storeRepository;+ private readonly IRepository<MeasureDimension> _measureDimensionRepository;+ private readonly IRepository<MeasureWeight> _measureWeightRepository;+ private readonly IRepository<MeasureUnit> _measureUnitRepository;+ private readonly IRepository<TaxCategory> _taxCategoryRepository;+ private readonly IRepository<Language> _languageRepository;+ private readonly IRepository<TranslationResource> _lsrRepository;+ private readonly IRepository<Log> _logRepository;+ private readonly IRepository<Currency> _currencyRepository;+ private readonly IRepository<Customer> _customerRepository;+ private readonly IRepository<CustomerGroup> _customerGroupRepository;+ private readonly IRepository<CustomerGroupProduct> _customerGroupProductRepository;+ private readonly IRepository<CustomerProduct> _customerProductRepository;+ private readonly IRepository<CustomerProductPrice> _customerProductPriceRepository;+ private readonly IRepository<CustomerTagProduct> _customerTagProductRepository;+ private readonly IRepository<CustomerHistoryPassword> _customerHistoryPasswordRepository;+ private readonly IRepository<CustomerNote> _customerNoteRepository;+ private readonly IRepository<UserApi> _userapiRepository;+ private readonly IRepository<SpecificationAttribute> _specificationAttributeRepository;+ private readonly IRepository<CheckoutAttribute> _checkoutAttributeRepository;+ private readonly IRepository<ProductAttribute> _productAttributeRepository;+ private readonly IRepository<Category> _categoryRepository;+ private readonly IRepository<Brand> _brandRepository;+ private readonly IRepository<Vendor> _vendorRepository;+ private readonly IRepository<Collection> _collectionRepository;+ private readonly IRepository<Product> _productRepository;+ private readonly IRepository<ProductReservation> _productReservationRepository;+ private readonly IRepository<ProductAlsoPurchased> _productalsopurchasedRepository;+ private readonly IRepository<EntityUrl> _entityUrlRepository;+ private readonly IRepository<EmailAccount> _emailAccountRepository;+ private readonly IRepository<MessageTemplate> _messageTemplateRepository;+ private readonly IRepository<Country> _countryRepository;+ private readonly IRepository<Discount> _discountRepository;+ private readonly IRepository<DiscountCoupon> _discountCouponRepository;+ private readonly IRepository<DiscountUsageHistory> _discountusageRepository;+ private readonly IRepository<BlogPost> _blogPostRepository;+ private readonly IRepository<Page> _pageRepository;+ private readonly IRepository<NewsItem> _newsItemRepository;+ private readonly IRepository<NewsLetterSubscription> _newslettersubscriptionRepository;+ private readonly IRepository<ShippingMethod> _shippingMethodRepository;+ private readonly IRepository<DeliveryDate> _deliveryDateRepository;+ private readonly IRepository<ActivityLogType> _activityLogTypeRepository;+ private readonly IRepository<ProductTag> _productTagRepository;+ private readonly IRepository<ProductReview> _productReviewRepository;+ private readonly IRepository<ProductLayout> _productLayoutRepository;+ private readonly IRepository<CategoryLayout> _categoryLayoutRepository;+ private readonly IRepository<BrandLayout> _brandLayoutRepository;+ private readonly IRepository<CollectionLayout> _collectionLayoutRepository;+ private readonly IRepository<PageLayout> _pageLayoutRepository;+ private readonly IRepository<ScheduleTask> _scheduleTaskRepository;+ private readonly IRepository<LoyaltyPointsHistory> _loyaltypointshistoryRepository;+ private readonly IRepository<SearchTerm> _searchtermRepository;+ private readonly IRepository<Setting> _settingRepository;+ private readonly IRepository<Shipment> _shipmentRepository;+ private readonly IRepository<Warehouse> _warehouseRepository;+ private readonly IRepository<PickupPoint> _pickupPointsRepository;+ private readonly IRepository<Permission> _permissionRepository;+ private readonly IRepository<PermissionAction> _permissionAction;+ private readonly IRepository<ExternalAuthentication> _externalAuthenticationRepository;+ private readonly IRepository<MerchandiseReturnReason> _merchandiseReturnReasonRepository;+ private readonly IRepository<MerchandiseReturnAction> _merchandiseReturnActionRepository;+ private readonly IRepository<ContactUs> _contactUsRepository;+ private readonly IRepository<CustomerAction> _customerAction;+ private readonly IRepository<CustomerActionType> _customerActionType;+ private readonly IRepository<CustomerActionHistory> _customerActionHistory;+ private readonly IRepository<PopupArchive> _popupArchive;+ private readonly IRepository<CustomerReminderHistory> _customerReminderHistoryRepository;+ private readonly IRepository<RecentlyViewedProduct> _recentlyViewedProductRepository;+ private readonly IRepository<KnowledgebaseArticle> _knowledgebaseArticleRepository;+ private readonly IRepository<KnowledgebaseCategory> _knowledgebaseCategoryRepository;+ private readonly IRepository<OrderTag> _orderTagRepository;+ private readonly IRepository<OrderStatus> _orderStatusRepository;private readonly IWebHostEnvironment _hostingEnvironment;private readonly IServiceProvider _serviceProvider;@@ -253,194 +252,191 @@ namespace Grand.Business.System.Services.Installationawait customerManagerService.ChangePassword(new ChangePasswordRequest(defaultUserEmail, false, PasswordFormat.Hashed, defaultUserPassword));}- private async Task CreateIndexes()+ private async Task CreateIndexes(MongoDBContext dbContext){//version- await _versionRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<GrandNodeVersion>((Builders<GrandNodeVersion>.IndexKeys.Ascending(x => x.DataBaseVersion)), new CreateIndexOptions() { Name = "DataBaseVersion", Unique = true }));+ await dbContext.CreateIndex(_versionRepository, OrderBuilder<GrandNodeVersion>.Create().Ascending(x => x.DataBaseVersion), "DataBaseVersion", true);//Store- await _storeRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Store>((Builders<Store>.IndexKeys.Ascending(x => x.DisplayOrder)), new CreateIndexOptions() { Name = "DisplayOrder" }));+ await dbContext.CreateIndex(_storeRepository, OrderBuilder<Store>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder");//Language- await _lsrRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<TranslationResource>((Builders<TranslationResource>.IndexKeys.Ascending(x => x.LanguageId).Ascending(x => x.Name)), new CreateIndexOptions() { Name = "Language" }));- await _lsrRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<TranslationResource>((Builders<TranslationResource>.IndexKeys.Ascending(x => x.Name)), new CreateIndexOptions() { Name = "ResourceName" }));+ await dbContext.CreateIndex(_lsrRepository, OrderBuilder<TranslationResource>.Create().Ascending(x => x.LanguageId).Ascending(x => x.Name), "Language");+ await dbContext.CreateIndex(_lsrRepository, OrderBuilder<TranslationResource>.Create().Ascending(x => x.Name), "ResourceName");//customer- await _customerRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Customer>((Builders<Customer>.IndexKeys.Descending(x => x.CreatedOnUtc).Ascending(x => x.Deleted).Ascending("CustomerGroups._id")), new CreateIndexOptions() { Name = "CreatedOnUtc_1_CustomerGroups._id_1", Unique = false }));- await _customerRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Customer>((Builders<Customer>.IndexKeys.Ascending(x => x.LastActivityDateUtc)), new CreateIndexOptions() { Name = "LastActivityDateUtc_1", Unique = false }));- await _customerRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Customer>((Builders<Customer>.IndexKeys.Ascending(x => x.CustomerGuid)), new CreateIndexOptions() { Name = "CustomerGuid_1", Unique = false }));- await _customerRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Customer>((Builders<Customer>.IndexKeys.Ascending(x => x.Email)), new CreateIndexOptions() { Name = "Email_1", Unique = false }));+ await dbContext.CreateIndex(_customerRepository, OrderBuilder<Customer>.Create().Descending(x => x.CreatedOnUtc).Ascending(x => x.Deleted), "CreatedOnUtc_1");+ await dbContext.CreateIndex(_customerRepository, OrderBuilder<Customer>.Create().Ascending(x => x.LastActivityDateUtc), "LastActivityDateUtc_1");+ await dbContext.CreateIndex(_customerRepository, OrderBuilder<Customer>.Create().Ascending(x => x.CustomerGuid), "CustomerGuid_1");+ await dbContext.CreateIndex(_customerRepository, OrderBuilder<Customer>.Create().Ascending(x => x.Email), "Email_1");- //customer group- await _customerGroupProductRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<CustomerGroupProduct>((Builders<CustomerGroupProduct>.IndexKeys.Ascending(x => x.Id).Ascending(x => x.DisplayOrder)), new CreateIndexOptions() { Name = "CustomerGroupId_DisplayOrder", Unique = false }));+ //product customer group+ await dbContext.CreateIndex(_customerGroupProductRepository, OrderBuilder<CustomerGroupProduct>.Create().Ascending(x => x.CustomerGroupId).Ascending(x => x.DisplayOrder), "CustomerGroupId_DisplayOrder");//customer personalize product- await _customerProductRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<CustomerProduct>((Builders<CustomerProduct>.IndexKeys.Ascending(x => x.CustomerId).Ascending(x => x.DisplayOrder)), new CreateIndexOptions() { Name = "CustomerProduct", Unique = false }));- await _customerProductRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<CustomerProduct>((Builders<CustomerProduct>.IndexKeys.Ascending(x => x.CustomerId).Ascending(x => x.ProductId)), new CreateIndexOptions() { Name = "CustomerProduct_Unique", Unique = true }));+ await dbContext.CreateIndex(_customerProductRepository, OrderBuilder<CustomerProduct>.Create().Ascending(x => x.CustomerId).Ascending(x => x.DisplayOrder), "CustomerProduct");+ await dbContext.CreateIndex(_customerProductRepository, OrderBuilder<CustomerProduct>.Create().Ascending(x => x.CustomerId).Ascending(x => x.ProductId), "CustomerProduct_Unique", true);//customer product price- await _customerProductPriceRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<CustomerProductPrice>((Builders<CustomerProductPrice>.IndexKeys.Ascending(x => x.CustomerId).Ascending(x => x.ProductId)), new CreateIndexOptions() { Name = "CustomerProduct", Unique = true }));+ await dbContext.CreateIndex(_customerProductPriceRepository, OrderBuilder<CustomerProductPrice>.Create().Ascending(x => x.CustomerId).Ascending(x => x.ProductId), "CustomerProduct", true);//customer tag history- await _customerTagProductRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<CustomerTagProduct>((Builders<CustomerTagProduct>.IndexKeys.Ascending(x => x.Id).Ascending(x => x.DisplayOrder)), new CreateIndexOptions() { Name = "CustomerTagId_DisplayOrder", Unique = false }));+ await dbContext.CreateIndex(_customerTagProductRepository, OrderBuilder<CustomerTagProduct>.Create().Ascending(x => x.Id).Ascending(x => x.DisplayOrder), "CustomerTagId_DisplayOrder");//customer history password- await _customerHistoryPasswordRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<CustomerHistoryPassword>((Builders<CustomerHistoryPassword>.IndexKeys.Ascending(x => x.CustomerId).Descending(x => x.CreatedOnUtc)), new CreateIndexOptions() { Name = "CustomerId", Unique = false }));+ await dbContext.CreateIndex(_customerHistoryPasswordRepository, OrderBuilder<CustomerHistoryPassword>.Create().Ascending(x => x.CustomerId).Descending(x => x.CreatedOnUtc), "CustomerId");//customer note- await _customerNoteRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<CustomerNote>((Builders<CustomerNote>.IndexKeys.Ascending(x => x.CustomerId).Descending(x => x.CreatedOnUtc)), new CreateIndexOptions() { Name = "CustomerId", Unique = false, Background = true }));+ await dbContext.CreateIndex(_customerNoteRepository, OrderBuilder<CustomerNote>.Create().Ascending(x => x.CustomerId).Descending(x => x.CreatedOnUtc), "CustomerId");//user api- await _userapiRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<UserApi>((Builders<UserApi>.IndexKeys.Ascending(x => x.Email)), new CreateIndexOptions() { Name = "Email", Unique = true, Background = true }));+ await dbContext.CreateIndex(_userapiRepository, OrderBuilder<UserApi>.Create().Ascending(x => x.Email), "Email", true);//specificationAttribute- await _specificationAttributeRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<SpecificationAttribute>((Builders<SpecificationAttribute>.IndexKeys.Ascending(x => x.DisplayOrder)), new CreateIndexOptions() { Name = "DisplayOrder" }));+ await dbContext.CreateIndex(_specificationAttributeRepository, OrderBuilder<SpecificationAttribute>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder");//checkoutAttribute- await _checkoutAttributeRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<CheckoutAttribute>((Builders<CheckoutAttribute>.IndexKeys.Ascending(x => x.DisplayOrder)), new CreateIndexOptions() { Name = "DisplayOrder" }));+ await dbContext.CreateIndex(_checkoutAttributeRepository, OrderBuilder<CheckoutAttribute>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder");//category- await _categoryRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Category>((Builders<Category>.IndexKeys.Ascending(x => x.ShowOnHomePage).Ascending(x => x.Published).Ascending(x => x.DisplayOrder)), new CreateIndexOptions() { Name = "ShowOnHomePage_DisplayOrder_1", Unique = false }));- await _categoryRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Category>((Builders<Category>.IndexKeys.Ascending(x => x.ParentCategoryId).Ascending(x => x.Published).Ascending(x => x.DisplayOrder)), new CreateIndexOptions() { Name = "ParentCategoryId_1_DisplayOrder_1", Unique = false }));- await _categoryRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Category>((Builders<Category>.IndexKeys.Ascending(x => x.FeaturedProductsOnHomePage).Ascending(x => x.Published).Ascending(x => x.DisplayOrder)), new CreateIndexOptions() { Name = "FeaturedProductsOnHomePage_DisplayOrder_1", Unique = false }));+ await dbContext.CreateIndex(_categoryRepository, OrderBuilder<Category>.Create().Ascending(x => x.ShowOnHomePage).Ascending(x => x.Published).Ascending(x => x.DisplayOrder), "ShowOnHomePage_DisplayOrder_1");+ await dbContext.CreateIndex(_categoryRepository, OrderBuilder<Category>.Create().Ascending(x => x.ParentCategoryId).Ascending(x => x.Published).Ascending(x => x.DisplayOrder), "ParentCategoryId_1_DisplayOrder_1");+ await dbContext.CreateIndex(_categoryRepository, OrderBuilder<Category>.Create().Ascending(x => x.FeaturedProductsOnHomePage).Ascending(x => x.Published).Ascending(x => x.DisplayOrder), "FeaturedProductsOnHomePage_DisplayOrder_1");//collection- await _collectionRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Collection>((Builders<Collection>.IndexKeys.Ascending(x => x.DisplayOrder)), new CreateIndexOptions() { Name = "DisplayOrder_1", Unique = false }));- await _collectionRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Collection>((Builders<Collection>.IndexKeys.Ascending("AppliedDiscounts")), new CreateIndexOptions() { Name = "AppliedDiscounts._id_1", Unique = false }));+ await dbContext.CreateIndex(_collectionRepository, OrderBuilder<Collection>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder_1");+ await dbContext.CreateIndex(_collectionRepository, OrderBuilder<Collection>.Create().Ascending(x => x.ShowOnHomePage).Ascending(x => x.Published).Ascending(x => x.DisplayOrder), "ShowOnHomePage_DisplayOrder_1");+ await dbContext.CreateIndex(_collectionRepository, OrderBuilder<Collection>.Create().Ascending(x => x.AppliedDiscounts), "AppliedDiscounts");//brands- await _brandRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Brand>((Builders<Brand>.IndexKeys.Ascending(x => x.DisplayOrder)), new CreateIndexOptions() { Name = "DisplayOrder_1", Unique = false }));- await _brandRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Brand>((Builders<Brand>.IndexKeys.Ascending("AppliedDiscounts")), new CreateIndexOptions() { Name = "AppliedDiscounts._id_1", Unique = false }));+ await dbContext.CreateIndex(_brandRepository, OrderBuilder<Brand>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder_1");+ await dbContext.CreateIndex(_brandRepository, OrderBuilder<Brand>.Create().Ascending(x => x.ShowOnHomePage).Ascending(x => x.Published).Ascending(x => x.DisplayOrder), "ShowOnHomePage_DisplayOrder_1");+ await dbContext.CreateIndex(_brandRepository, OrderBuilder<Brand>.Create().Ascending(x => x.AppliedDiscounts), "AppliedDiscounts");//Product- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending(x => x.MarkAsNew).Ascending(x => x.CreatedOnUtc)), new CreateIndexOptions() { Name = "MarkAsNew_1_CreatedOnUtc_1", Unique = false }));- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending(x => x.Published).Ascending(x => x.ShowOnHomePage).Ascending(x => x.DisplayOrder).Ascending(x => x.Name)), new CreateIndexOptions() { Name = "ShowOnHomePage_1_Published_1", Unique = false }));- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending(x => x.Published).Ascending(x => x.BestSeller).Ascending(x => x.DisplayOrder).Ascending(x => x.Name)), new CreateIndexOptions() { Name = "ShowOnBestSeller_1_Published_1", Unique = false }));- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending(x => x.ParentGroupedProductId).Ascending(x => x.DisplayOrder)), new CreateIndexOptions() { Name = "ParentGroupedProductId_1_DisplayOrder_1", Unique = false }));- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending(x => x.ProductTags).Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.Name)), new CreateIndexOptions() { Name = "ProductTags._id_1_Name_1", Unique = false }));- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending(x => x.Name)), new CreateIndexOptions() { Name = "Name_1", Unique = false }));-- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending("ProductCategories.DisplayOrder")), new CreateIndexOptions() { Name = "ProductCategories.CategoryId_1_DisplayOrder_1", Unique = false }));- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.DisplayOrderCategory).Ascending("ProductCategories.CategoryId")), new CreateIndexOptions() { Name = "ProductCategories.CategoryId_1_OrderCategory_1", Unique = false }));- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.Name).Ascending("ProductCategories.CategoryId")), new CreateIndexOptions() { Name = "ProductCategories.CategoryId_1_Name_1", Unique = false }));- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.Price).Ascending("ProductCategories.CategoryId")), new CreateIndexOptions() { Name = "ProductCategories.CategoryId_1_Price_1", Unique = false }));- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.Sold).Ascending("ProductCategories.CategoryId")), new CreateIndexOptions() { Name = "ProductCategories.CategoryId_1_Sold_1", Unique = false }));- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending("ProductCategories.CategoryId").Ascending("ProductCategories.IsFeaturedProduct")), new CreateIndexOptions() { Name = "ProductCategories.CategoryId_1_IsFeaturedProduct_1", Unique = false }));-- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending("ProductCollections.CollectionId").Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.DisplayOrderCollection)), new CreateIndexOptions() { Name = "ProductCollections.CollectionId_1_OrderCategory_1", Unique = false }));- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending("ProductCollections.CollectionId").Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.Name)), new CreateIndexOptions() { Name = "ProductCollections.CollectionId_1_Name_1", Unique = false }));- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending("ProductCollections.CollectionId").Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.Sold)), new CreateIndexOptions() { Name = "ProductCollections.CollectionId_1_Sold_1", Unique = false }));- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending("ProductCollections.CollectionId").Ascending("ProductCollections.IsFeaturedProduct").Ascending(x => x.Published).Ascending(x => x.VisibleIndividually)), new CreateIndexOptions() { Name = "ProductCollections.CollectionId_1_IsFeaturedProduct_1", Unique = false }));-- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.BrandId).Ascending(x => x.DisplayOrderBrand)), new CreateIndexOptions() { Name = "ProductBrand", Unique = false }));-- await _productRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Product>((Builders<Product>.IndexKeys.Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending("ProductSpecificationAttributes.SpecificationAttributeOptionId").Ascending("ProductSpecificationAttributes.AllowFiltering")), new CreateIndexOptions() { Name = "ProductSpecificationAttributes", Unique = false }));+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending(x => x.MarkAsNew).Ascending(x => x.CreatedOnUtc), "MarkAsNew_1_CreatedOnUtc_1");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending(x => x.Published).Ascending(x => x.ShowOnHomePage).Ascending(x => x.DisplayOrder).Ascending(x => x.Name), "ShowOnHomePage_1_Published_1");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending(x => x.Published).Ascending(x => x.BestSeller).Ascending(x => x.DisplayOrder).Ascending(x => x.Name), "ShowOnBestSeller_1_Published_1");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending(x => x.ParentGroupedProductId).Ascending(x => x.DisplayOrder), "ParentGroupedProductId_1_DisplayOrder_1");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending(x => x.ProductTags).Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.Name), "ProductTags._id_1_Name_1");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending(x => x.Name), "Name_1");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending("ProductCategories.DisplayOrder"), "CategoryId_1_DisplayOrder_1");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.DisplayOrderCategory).Ascending("ProductCategories.CategoryId"), "ProductCategories.CategoryId_1_OrderCategory_1");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.Name).Ascending("ProductCategories.CategoryId"), "ProductCategories.CategoryId_1_Name_1");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.Price).Ascending("ProductCategories.CategoryId"), "ProductCategories.CategoryId_1_Price_1");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.Sold).Ascending("ProductCategories.CategoryId"), "ProductCategories.CategoryId_1_Sold_1");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending("ProductCategories.CategoryId").Ascending("ProductCategories.IsFeaturedProduct"), "ProductCategories.CategoryId_1_IsFeaturedProduct_1");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending("ProductCollections.CollectionId").Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.DisplayOrderCollection), "ProductCollections.CollectionId_1_OrderCategory_1");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending("ProductCollections.CollectionId").Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.Name), "ProductCollections.CollectionId_1_Name_1");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending("ProductCollections.CollectionId").Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.Sold), "ProductCollections.CollectionId_1_Sold_1");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending("ProductCollections.CollectionId").Ascending("ProductCollections.IsFeaturedProduct").Ascending(x => x.Published).Ascending(x => x.VisibleIndividually), "ProductCollections.CollectionId_1_IsFeaturedProduct_1");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending(x => x.BrandId).Ascending(x => x.DisplayOrderBrand), "ProductBrand");+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending(x => x.Published).Ascending(x => x.VisibleIndividually).Ascending("ProductSpecificationAttributes.SpecificationAttributeOptionId").Ascending("ProductSpecificationAttributes.AllowFiltering"), "ProductSpecificationAttributes");//productreseration- await _productReservationRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<ProductReservation>((Builders<ProductReservation>.IndexKeys.Ascending(x => x.ProductId).Ascending(x => x.Date)), new CreateIndexOptions() { Name = "ProductReservation", Unique = false }));+ await dbContext.CreateIndex(_productReservationRepository, OrderBuilder<ProductReservation>.Create().Ascending(x => x.ProductId).Ascending(x => x.Date), "ProductReservation");//bid- await _bidRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Bid>((Builders<Bid>.IndexKeys.Ascending(x => x.ProductId).Ascending(x => x.CustomerId).Descending(x => x.Date)), new CreateIndexOptions() { Name = "ProductCustomer", Unique = false }));- await _bidRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Bid>((Builders<Bid>.IndexKeys.Ascending(x => x.ProductId).Descending(x => x.Date)), new CreateIndexOptions() { Name = "ProductDate", Unique = false }));+ await dbContext.CreateIndex(_bidRepository, OrderBuilder<Bid>.Create().Ascending(x => x.ProductId).Ascending(x => x.CustomerId).Descending(x => x.Date), "ProductCustomer");+ await dbContext.CreateIndex(_bidRepository, OrderBuilder<Bid>.Create().Ascending(x => x.ProductId).Descending(x => x.Date), "ProductDate");//ProductReview- await _productReviewRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<ProductReview>((Builders<ProductReview>.IndexKeys.Ascending(x => x.ProductId).Ascending(x => x.CreatedOnUtc)), new CreateIndexOptions() { Name = "ProductId", Unique = false }));+ await dbContext.CreateIndex(_productReviewRepository, OrderBuilder<ProductReview>.Create().Ascending(x => x.ProductId).Ascending(x => x.CreatedOnUtc), "ProductId");//Recently Viewed Products- await _recentlyViewedProductRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<RecentlyViewedProduct>((Builders<RecentlyViewedProduct>.IndexKeys.Ascending(x => x.CustomerId).Ascending(x => x.ProductId).Descending(x => x.CreatedOnUtc)), new CreateIndexOptions() { Name = "CustomerId.ProductId" }));+ await dbContext.CreateIndex(_recentlyViewedProductRepository, OrderBuilder<RecentlyViewedProduct>.Create().Ascending(x => x.CustomerId).Ascending(x => x.ProductId).Descending(x => x.CreatedOnUtc), "CustomerId.ProductId");//Product also purchased- await _productalsopurchasedRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<ProductAlsoPurchased>((Builders<ProductAlsoPurchased>.IndexKeys.Ascending(x => x.ProductId)), new CreateIndexOptions() { Name = "ProductId", Unique = false, Background = true }));+ await dbContext.CreateIndex(_productalsopurchasedRepository, OrderBuilder<ProductAlsoPurchased>.Create().Ascending(x => x.ProductId), "ProductId");//url record- await _entityUrlRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<EntityUrl>((Builders<EntityUrl>.IndexKeys.Ascending(x => x.Slug).Ascending(x => x.IsActive)), new CreateIndexOptions() { Name = "Slug" }));- await _entityUrlRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<EntityUrl>((Builders<EntityUrl>.IndexKeys.Ascending(x => x.EntityId).Ascending(x => x.EntityName).Ascending(x => x.LanguageId).Ascending(x => x.IsActive)), new CreateIndexOptions() { Name = "UrlEntity" }));-+ await dbContext.CreateIndex(_entityUrlRepository, OrderBuilder<EntityUrl>.Create().Ascending(x => x.Slug).Ascending(x => x.IsActive), "Slug");+ await dbContext.CreateIndex(_entityUrlRepository, OrderBuilder<EntityUrl>.Create().Ascending(x => x.EntityId).Ascending(x => x.EntityName).Ascending(x => x.LanguageId).Ascending(x => x.IsActive), "UrlEntity");//message template- await _messageTemplateRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<MessageTemplate>((Builders<MessageTemplate>.IndexKeys.Ascending(x => x.Name)), new CreateIndexOptions() { Name = "Name", Unique = false }));+ await dbContext.CreateIndex(_messageTemplateRepository, OrderBuilder<MessageTemplate>.Create().Ascending(x => x.Name), "Name");// Country and Stateprovince- await _countryRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Country>((Builders<Country>.IndexKeys.Ascending(x => x.DisplayOrder)), new CreateIndexOptions() { Name = "DisplayOrder" }));+ await dbContext.CreateIndex(_countryRepository, OrderBuilder<Country>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder");//discount- await _discountCouponRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<DiscountCoupon>((Builders<DiscountCoupon>.IndexKeys.Ascending(x => x.CouponCode)), new CreateIndexOptions() { Name = "CouponCode", Unique = true }));- await _discountCouponRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<DiscountCoupon>((Builders<DiscountCoupon>.IndexKeys.Ascending(x => x.DiscountId)), new CreateIndexOptions() { Name = "DiscountId", Unique = false }));+ await dbContext.CreateIndex(_discountCouponRepository, OrderBuilder<DiscountCoupon>.Create().Ascending(x => x.CouponCode), "CouponCode", true);+ await dbContext.CreateIndex(_discountCouponRepository, OrderBuilder<DiscountCoupon>.Create().Ascending(x => x.DiscountId), "DiscountId");- await _discountusageRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<DiscountUsageHistory>((Builders<DiscountUsageHistory>.IndexKeys.Ascending(x => x.CustomerId)), new CreateIndexOptions() { Name = "CustomerId" }));- await _discountusageRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<DiscountUsageHistory>((Builders<DiscountUsageHistory>.IndexKeys.Ascending(x => x.DiscountId)), new CreateIndexOptions() { Name = "DiscountId" }));- await _discountusageRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<DiscountUsageHistory>((Builders<DiscountUsageHistory>.IndexKeys.Ascending(x => x.OrderId)), new CreateIndexOptions() { Name = "OrderId" }));+ await dbContext.CreateIndex(_discountusageRepository, OrderBuilder<DiscountUsageHistory>.Create().Ascending(x => x.CustomerId), "CustomerId");+ await dbContext.CreateIndex(_discountusageRepository, OrderBuilder<DiscountUsageHistory>.Create().Ascending(x => x.DiscountId), "DiscountId");+ await dbContext.CreateIndex(_discountusageRepository, OrderBuilder<DiscountUsageHistory>.Create().Ascending(x => x.OrderId), "OrderId");//knowledgebase- await _knowledgebaseArticleRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<KnowledgebaseArticle>((Builders<KnowledgebaseArticle>.IndexKeys.Ascending(x => x.DisplayOrder)), new CreateIndexOptions() { Name = "DisplayOrder", Unique = false }));- await _knowledgebaseCategoryRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<KnowledgebaseCategory>((Builders<KnowledgebaseCategory>.IndexKeys.Ascending(x => x.DisplayOrder)), new CreateIndexOptions() { Name = "DisplayOrder", Unique = false }));+ await dbContext.CreateIndex(_knowledgebaseArticleRepository, OrderBuilder<KnowledgebaseArticle>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder");+ await dbContext.CreateIndex(_knowledgebaseCategoryRepository, OrderBuilder<KnowledgebaseCategory>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder");//page- await _pageRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Page>((Builders<Page>.IndexKeys.Ascending(x => x.SystemName)), new CreateIndexOptions() { Name = "SystemName", Unique = false }));+ await dbContext.CreateIndex(_pageRepository, OrderBuilder<Page>.Create().Ascending(x => x.SystemName), "SystemName");//news- await _newsItemRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<NewsItem>((Builders<NewsItem>.IndexKeys.Descending(x => x.CreatedOnUtc)), new CreateIndexOptions() { Name = "CreatedOnUtc", Unique = false }));+ await dbContext.CreateIndex(_newsItemRepository, OrderBuilder<NewsItem>.Create().Ascending(x => x.CreatedOnUtc), "CreatedOnUtc");//newsletter- await _newslettersubscriptionRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<NewsLetterSubscription>((Builders<NewsLetterSubscription>.IndexKeys.Ascending(x => x.CustomerId)), new CreateIndexOptions() { Name = "CustomerId", Unique = false }));- await _newslettersubscriptionRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<NewsLetterSubscription>((Builders<NewsLetterSubscription>.IndexKeys.Ascending(x => x.Email)), new CreateIndexOptions() { Name = "Email", Unique = false }));+ await dbContext.CreateIndex(_newslettersubscriptionRepository, OrderBuilder<NewsLetterSubscription>.Create().Ascending(x => x.CustomerId), "CustomerId");+ await dbContext.CreateIndex(_newslettersubscriptionRepository, OrderBuilder<NewsLetterSubscription>.Create().Ascending(x => x.Email), "Email");//Log- await _logRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Log>((Builders<Log>.IndexKeys.Descending(x => x.CreatedOnUtc)), new CreateIndexOptions() { Name = "CreatedOnUtc", Unique = false }));+ await dbContext.CreateIndex(_logRepository, OrderBuilder<Log>.Create().Ascending(x => x.CreatedOnUtc), "CreatedOnUtc");//Campaign history- await _campaignHistoryRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<CampaignHistory>((Builders<CampaignHistory>.IndexKeys.Ascending(x => x.CampaignId).Descending(x => x.CreatedDateUtc)), new CreateIndexOptions() { Name = "CampaignId", Unique = false }));+ await dbContext.CreateIndex(_campaignHistoryRepository, OrderBuilder<CampaignHistory>.Create().Ascending(x => x.CampaignId).Descending(x => x.CreatedDateUtc), "CampaignId");//loyalty points- await _loyaltypointshistoryRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<LoyaltyPointsHistory>((Builders<LoyaltyPointsHistory>.IndexKeys.Ascending(x => x.CustomerId)), new CreateIndexOptions() { Name = "CustomerId" }));+ await dbContext.CreateIndex(_loyaltypointshistoryRepository, OrderBuilder<LoyaltyPointsHistory>.Create().Ascending(x => x.CustomerId), "CustomerId");//search term- await _searchtermRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<SearchTerm>((Builders<SearchTerm>.IndexKeys.Descending(x => x.Count)), new CreateIndexOptions() { Name = "Count", Unique = false }));+ await dbContext.CreateIndex(_searchtermRepository, OrderBuilder<SearchTerm>.Create().Descending(x => x.Count), "Count");//setting- await _settingRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Setting>((Builders<Setting>.IndexKeys.Ascending(x => x.Name)), new CreateIndexOptions() { Name = "Name", Unique = false }));+ await dbContext.CreateIndex(_settingRepository, OrderBuilder<Setting>.Create().Ascending(x => x.Name), "Name");//shipment- await _shipmentRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Shipment>((Builders<Shipment>.IndexKeys.Ascending(x => x.ShipmentNumber)), new CreateIndexOptions() { Name = "ShipmentNumber", Unique = true }));- await _shipmentRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Shipment>((Builders<Shipment>.IndexKeys.Ascending(x => x.OrderId)), new CreateIndexOptions() { Name = "OrderId" }));+ await dbContext.CreateIndex(_shipmentRepository, OrderBuilder<Shipment>.Create().Ascending(x => x.ShipmentNumber), "ShipmentNumber", true);+ await dbContext.CreateIndex(_shipmentRepository, OrderBuilder<Shipment>.Create().Ascending(x => x.OrderId), "OrderId");//order- await _orderRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Order>((Builders<Order>.IndexKeys.Ascending(x => x.CustomerId).Descending(x => x.CreatedOnUtc)), new CreateIndexOptions() { Name = "CustomerId_1_CreatedOnUtc_-1", Unique = false }));- await _orderRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Order>((Builders<Order>.IndexKeys.Descending(x => x.CreatedOnUtc)), new CreateIndexOptions() { Name = "CreatedOnUtc_-1", Unique = false }));- await _orderRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Order>((Builders<Order>.IndexKeys.Descending(x => x.OrderNumber)), new CreateIndexOptions() { Name = "OrderNumber", Unique = false }));- await _orderRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Order>((Builders<Order>.IndexKeys.Ascending(x => x.Code)), new CreateIndexOptions() { Name = "OrderCode", Unique = false }));- await _orderRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Order>((Builders<Order>.IndexKeys.Ascending("OrderItems.ProductId")), new CreateIndexOptions() { Name = "OrderItemsProductId" }));- await _orderRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Order>((Builders<Order>.IndexKeys.Ascending("OrderItems._id")), new CreateIndexOptions() { Name = "OrderItemId" }));+ await dbContext.CreateIndex(_orderRepository, OrderBuilder<Order>.Create().Ascending(x => x.CustomerId).Descending(x => x.CreatedOnUtc), "CustomerId_1_CreatedOnUtc_-1");+ await dbContext.CreateIndex(_orderRepository, OrderBuilder<Order>.Create().Descending(x => x.CreatedOnUtc), "CreatedOnUtc_-1");+ await dbContext.CreateIndex(_orderRepository, OrderBuilder<Order>.Create().Descending(x => x.OrderNumber), "OrderNumber");+ await dbContext.CreateIndex(_orderRepository, OrderBuilder<Order>.Create().Ascending(x => x.Code), "OrderCode");+ await dbContext.CreateIndex(_orderRepository, OrderBuilder<Order>.Create().Ascending("OrderItems.ProductId"), "OrderItemProductId");+ await dbContext.CreateIndex(_orderRepository, OrderBuilder<Order>.Create().Ascending("OrderItems.Id"), "OrderItems._id");- await _orderStatusRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<OrderStatus>((Builders<OrderStatus>.IndexKeys.Ascending(x => x.StatusId)), new CreateIndexOptions() { Name = "StatusId", Unique = true }));+ await dbContext.CreateIndex(_orderStatusRepository, OrderBuilder<OrderStatus>.Create().Ascending(x => x.StatusId), "StatusId", true);- await _orderNoteRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<OrderNote>((Builders<OrderNote>.IndexKeys.Ascending(x => x.OrderId).Descending(x => x.CreatedOnUtc)), new CreateIndexOptions() { Name = "Id", Unique = false, Background = true }));+ await dbContext.CreateIndex(_orderNoteRepository, OrderBuilder<OrderNote>.Create().Ascending(x => x.OrderId).Descending(x => x.CreatedOnUtc), "OrderId_Created");//permision- await _permissionRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<Permission>((Builders<Permission>.IndexKeys.Ascending(x => x.SystemName)), new CreateIndexOptions() { Name = "SystemName", Unique = true }));- await _permissionAction.Collection.Indexes.CreateOneAsync(new CreateIndexModel<PermissionAction>((Builders<PermissionAction>.IndexKeys.Ascending(x => x.SystemName)), new CreateIndexOptions() { Name = "SystemName", Unique = false }));+ await dbContext.CreateIndex(_permissionRepository, OrderBuilder<Permission>.Create().Ascending(x => x.SystemName), "SystemName", true);++ await dbContext.CreateIndex(_permissionAction, OrderBuilder<PermissionAction>.Create().Ascending(x => x.SystemName), "SystemName");//externalauth- await _externalAuthenticationRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<ExternalAuthentication>((Builders<ExternalAuthentication>.IndexKeys.Ascending(x => x.CustomerId)), new CreateIndexOptions() { Name = "CustomerId" }));+ await dbContext.CreateIndex(_externalAuthenticationRepository, OrderBuilder<ExternalAuthentication>.Create().Ascending(x => x.CustomerId), "CustomerId");//merchandise return- await _merchandiseReturnRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<MerchandiseReturn>((Builders<MerchandiseReturn>.IndexKeys.Ascending(x => x.ReturnNumber)), new CreateIndexOptions() { Name = "ReturnNumber", Unique = true }));- await _merchandiseReturnNoteRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<MerchandiseReturnNote>((Builders<MerchandiseReturnNote>.IndexKeys.Ascending(x => x.MerchandiseReturnId).Descending(x => x.CreatedOnUtc)), new CreateIndexOptions() { Name = "Id", Unique = false, Background = true }));+ await dbContext.CreateIndex(_merchandiseReturnRepository, OrderBuilder<MerchandiseReturn>.Create().Ascending(x => x.ReturnNumber), "ReturnNumber", true);+ await dbContext.CreateIndex(_merchandiseReturnNoteRepository, OrderBuilder<MerchandiseReturnNote>.Create().Ascending(x => x.MerchandiseReturnId).Descending(x => x.CreatedOnUtc), "MerchandiseReturnId_CreatedOn");//contactus- await _contactUsRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<ContactUs>((Builders<ContactUs>.IndexKeys.Ascending(x => x.Email)), new CreateIndexOptions() { Name = "Email", Unique = false }));- await _contactUsRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<ContactUs>((Builders<ContactUs>.IndexKeys.Descending(x => x.CreatedOnUtc)), new CreateIndexOptions() { Name = "CreatedOnUtc", Unique = false }));+ await dbContext.CreateIndex(_contactUsRepository, OrderBuilder<ContactUs>.Create().Ascending(x => x.Email), "Email");+ await dbContext.CreateIndex(_contactUsRepository, OrderBuilder<ContactUs>.Create().Descending(x => x.CreatedOnUtc), "CreatedOnUtc");//customer action- await _customerAction.Collection.Indexes.CreateOneAsync(new CreateIndexModel<CustomerAction>((Builders<CustomerAction>.IndexKeys.Ascending(x => x.ActionTypeId)), new CreateIndexOptions() { Name = "ActionTypeId", Unique = false }));-- await _customerActionHistory.Collection.Indexes.CreateOneAsync(new CreateIndexModel<CustomerActionHistory>((Builders<CustomerActionHistory>.IndexKeys.Ascending(x => x.CustomerId).Ascending(x => x.CustomerActionId)), new CreateIndexOptions() { Name = "Customer_Action", Unique = false }));+ await dbContext.CreateIndex(_customerAction, OrderBuilder<CustomerAction>.Create().Ascending(x => x.ActionTypeId), "ActionTypeId");+ await dbContext.CreateIndex(_customerActionHistory, OrderBuilder<CustomerActionHistory>.Create().Ascending(x => x.CustomerId).Ascending(x => x.CustomerActionId), "Customer_Action");//banner- await _popupArchive.Collection.Indexes.CreateOneAsync(new CreateIndexModel<PopupArchive>((Builders<PopupArchive>.IndexKeys.Ascending(x => x.CustomerActionId)), new CreateIndexOptions() { Name = "CustomerActionId", Unique = false }));+ await dbContext.CreateIndex(_popupArchive, OrderBuilder<PopupArchive>.Create().Ascending(x => x.CustomerActionId), "CustomerActionId");//customer reminder- await _customerReminderHistoryRepository.Collection.Indexes.CreateOneAsync(new CreateIndexModel<CustomerReminderHistory>((Builders<CustomerReminderHistory>.IndexKeys.Ascending(x => x.CustomerId).Ascending(x => x.CustomerReminderId)), new CreateIndexOptions() { Name = "CustomerId", Unique = false }));+ await dbContext.CreateIndex(_customerReminderHistoryRepository, OrderBuilder<CustomerReminderHistory>.Create().Ascending(x => x.CustomerId).Ascending(x => x.CustomerReminderId), "CustomerId");}private async Task CreateTables(string local)@@ -450,23 +446,19 @@ namespace Grand.Business.System.Services.Installationtry{- var options = new CreateCollectionOptions();- var collation = new Collation(local);- options.Collation = collation;var connectionString = DataSettingsManager.LoadSettings().ConnectionString;-- var mongourl = new MongoUrl(connectionString);- var databaseName = mongourl.DatabaseName;- var mongodb = new MongoClient(connectionString).GetDatabase(databaseName);- var dbContext = new MongoDBContext(mongodb);+ var dbContext = new MongoDBContext(connectionString);var typeSearcher = _serviceProvider.GetRequiredService<ITypeSearcher>();var q = typeSearcher.GetAssemblies().FirstOrDefault(x => x.GetName().Name == "Grand.Domain");+foreach (var item in q.GetTypes()){if (item.BaseType != null && item.IsClass && item.BaseType == typeof(BaseEntity))- await dbContext.Database().CreateCollectionAsync(item.Name, options);+ await dbContext.CreateTable(item.Name, local);}+ await CreateIndexes(dbContext);+}catch (Exception ex){@@ -486,7 +478,6 @@ namespace Grand.Business.System.Services.InstallationdefaultUserEmail = defaultUserEmail.ToLower();await CreateTables(collation);- await CreateIndexes();await InstallVersion();await InstallMenuAdminSiteMap();await InstallStores(companyName, companyAddress, companyPhoneNumber, companyEmail);diff --git a/src/Core/Grand.Domain/Data/IDatabaseContext.cs b/src/Core/Grand.Domain/Data/IDatabaseContext.csindex 0b2efc18c..68026aefb 100644--- a/src/Core/Grand.Domain/Data/IDatabaseContext.cs+++ b/src/Core/Grand.Domain/Data/IDatabaseContext.cs@@ -9,5 +9,7 @@ namespace Grand.Domain.DataTask<byte[]> GridFSBucketDownload(string id);Task<string> GridFSBucketUploadFromBytesAsync(string filename, byte[] source);Task<bool> DatabaseExist(string connectionString);+ Task CreateTable(string name, string collation);+ Task CreateIndex<T>(IRepository<T> repository, OrderBuilder<T> orderBuilder, string indexName, bool unique = false) where T : BaseEntity;}}diff --git a/src/Core/Grand.Domain/Data/Mongo/MongoDBContext.cs b/src/Core/Grand.Domain/Data/Mongo/MongoDBContext.csindex ac7e9bf91..6853fa7bc 100644--- a/src/Core/Grand.Domain/Data/Mongo/MongoDBContext.cs+++ b/src/Core/Grand.Domain/Data/Mongo/MongoDBContext.cs@@ -1,5 +1,6 @@using MongoDB.Bson;using MongoDB.Driver;+using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;@@ -13,6 +14,12 @@ namespace Grand.Domain.Data.Mongo{}+ public MongoDBContext(string connectionString)+ {+ var mongourl = new MongoUrl(connectionString);+ var databaseName = mongourl.DatabaseName;+ _database = new MongoClient(connectionString).GetDatabase(databaseName);+ }public MongoDBContext(IMongoDatabase mongodatabase){@@ -68,5 +75,47 @@ namespace Grand.Domain.Data.Mongoelsereturn false;}++ public async Task CreateTable(string name, string collation)+ {+ var options = new CreateCollectionOptions();+ options.Collation = new Collation(collation);+ var database = _database ?? TryReadMongoDatabase();+ await database.CreateCollectionAsync(name, options);++ }++ public async Task CreateIndex<T>(IRepository<T> repository, OrderBuilder<T> orderBuilder, string indexName, bool unique = false) where T : BaseEntity+ {+ IList<IndexKeysDefinition<T>> keys = new List<IndexKeysDefinition<T>>();+ foreach (var item in orderBuilder.Fields)+ {+ if (item.selector != null)+ {+ if (item.value)+ {+ keys.Add(Builders<T>.IndexKeys.Ascending(item.selector));+ }+ else+ {+ keys.Add(Builders<T>.IndexKeys.Descending(item.selector));+ }+ }+ else+ {+ if (item.value)+ {+ keys.Add(Builders<T>.IndexKeys.Ascending(item.fieldName));+ }+ else+ {+ keys.Add(Builders<T>.IndexKeys.Descending(item.fieldName));+ }+ }+ }++ await ((MongoRepository<T>)repository).Collection.Indexes.CreateOneAsync(new CreateIndexModel<T>(Builders<T>.IndexKeys.Combine(keys),+ new CreateIndexOptions() { Name = indexName, Unique = unique }));+ }}}diff --git a/src/Core/Grand.Domain/Data/OrderBuilder.cs b/src/Core/Grand.Domain/Data/OrderBuilder.csnew file mode 100644index 000000000..bb05cfb5b--- /dev/null+++ b/src/Core/Grand.Domain/Data/OrderBuilder.cs@@ -0,0 +1,48 @@+using System;+using System.Collections.Generic;+using System.Linq.Expressions;++namespace Grand.Domain.Data+{+ public class OrderBuilder<T>+ {+ private readonly List<(Expression<Func<T, object>> selector, bool value, string fieldName)> _list = new();++ protected OrderBuilder() { }++ public static OrderBuilder<T> Create()+ {+ return new();+ }++ public OrderBuilder<T> Ascending(Expression<Func<T, object>> selector)+ {+ _list.Add((selector, true, ""));++ return this;+ }+ public OrderBuilder<T> Ascending(string fieldName)+ {+ _list.Add((null, true, fieldName));++ return this;+ }++ public OrderBuilder<T> Descending(Expression<Func<T, object>> selector)+ {+ _list.Add((selector, false, ""));++ return this;+ }+ public OrderBuilder<T> Descending(string fieldName)+ {+ _list.Add((null, false, fieldName));++ return this;+ }++ public IEnumerable<(Expression<Func<T, object>> selector, bool value, string fieldName)> Fields {+ get { return _list; }+ }+ }+}