Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Further improvements for support CosmosDB

KrzysztofPajak16678c20789e
diff --git a/src/Business/Grand.Business.Checkout/Services/Orders/MerchandiseReturnService.cs b/src/Business/Grand.Business.Checkout/Services/Orders/MerchandiseReturnService.cs
index a07a1ea88..909bd8333 100644
--- a/src/Business/Grand.Business.Checkout/Services/Orders/MerchandiseReturnService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Orders/MerchandiseReturnService.cs
@@ -127,7 +127,7 @@ namespace Grand.Business.Checkout.Services.Orders
return await _cacheBase.GetAsync(CacheKey.MERCHANDISE_RETURN_ACTIONS_ALL_KEY, async () =>
{
var query = from rra in _merchandiseReturnActionRepository.Table
- orderby rra.DisplayOrder, rra.Id
+ orderby rra.DisplayOrder
select rra;
return await Task.FromResult(query.ToList());
});
@@ -270,7 +270,7 @@ namespace Grand.Business.Checkout.Services.Orders
return await _cacheBase.GetAsync(CacheKey.MERCHANDISE_RETURN_REASONS_ALL_KEY, async () =>
{
var query = from rra in _merchandiseReturnReasonRepository.Table
- orderby rra.DisplayOrder, rra.Id
+ orderby rra.DisplayOrder
select rra;
return await Task.FromResult(query.ToList());
});
diff --git a/src/Business/Grand.Business.Common/Services/Directory/SearchTermService.cs b/src/Business/Grand.Business.Common/Services/Directory/SearchTermService.cs
index 1fc4c2769..e64212a12 100644
--- a/src/Business/Grand.Business.Common/Services/Directory/SearchTermService.cs
+++ b/src/Business/Grand.Business.Common/Services/Directory/SearchTermService.cs
@@ -74,7 +74,6 @@ namespace Grand.Business.Common.Services.Directory
var query = from st in _searchTermRepository.Table
where st.Keyword == keyword && st.StoreId == storeId
- orderby st.Id
select st;
return await Task.FromResult(query.FirstOrDefault());
}
diff --git a/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs b/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs
index b4a7d7ab4..d1376c53e 100644
--- a/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs
+++ b/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs
@@ -115,7 +115,6 @@ namespace Grand.Business.Common.Services.Security
var query = from pr in _permissionRepository.Table
where pr.SystemName == systemName
- orderby pr.Id
select pr;
return await Task.FromResult(query.FirstOrDefault());
diff --git a/src/Business/Grand.Business.Customers/Services/AffiliateService.cs b/src/Business/Grand.Business.Customers/Services/AffiliateService.cs
index 409a4e98f..fcb936b08 100644
--- a/src/Business/Grand.Business.Customers/Services/AffiliateService.cs
+++ b/src/Business/Grand.Business.Customers/Services/AffiliateService.cs
@@ -63,7 +63,6 @@ namespace Grand.Business.Customers.Services
public virtual async Task<Affiliate> GetAffiliateByFriendlyUrlName(string friendlyUrlName)
{
var query = from a in _affiliateRepository.Table
- orderby a.Id
where a.FriendlyUrlName.Contains(friendlyUrlName.ToLowerInvariant())
select a;
var affiliate = await Task.FromResult(query.FirstOrDefault());
diff --git a/src/Business/Grand.Business.Marketing/Services/Newsletters/NewsLetterSubscriptionService.cs b/src/Business/Grand.Business.Marketing/Services/Newsletters/NewsLetterSubscriptionService.cs
index ca3005740..fde844b58 100644
--- a/src/Business/Grand.Business.Marketing/Services/Newsletters/NewsLetterSubscriptionService.cs
+++ b/src/Business/Grand.Business.Marketing/Services/Newsletters/NewsLetterSubscriptionService.cs
@@ -176,7 +176,6 @@ namespace Grand.Business.Marketing.Services.Newsteletters
var newsLetterSubscriptions = from nls in _subscriptionRepository.Table
where nls.NewsLetterSubscriptionGuid == newsLetterSubscriptionGuid
- orderby nls.Id
select nls;
return await Task.FromResult(newsLetterSubscriptions.FirstOrDefault());
@@ -197,7 +196,6 @@ namespace Grand.Business.Marketing.Services.Newsteletters
var newsLetterSubscriptions = from nls in _subscriptionRepository.Table
where nls.Email.ToLower() == email.ToLower() && nls.StoreId == storeId
- orderby nls.Id
select nls;
return await Task.FromResult(newsLetterSubscriptions.FirstOrDefault());
@@ -215,7 +213,6 @@ namespace Grand.Business.Marketing.Services.Newsteletters
var newsLetterSubscriptions = from nls in _subscriptionRepository.Table
where nls.CustomerId == customerId
- orderby nls.Id
select nls;
return await Task.FromResult(newsLetterSubscriptions.FirstOrDefault());
diff --git a/src/Business/Grand.Business.Messages/Services/EmailAccountService.cs b/src/Business/Grand.Business.Messages/Services/EmailAccountService.cs
index be6703099..7d8d6f380 100644
--- a/src/Business/Grand.Business.Messages/Services/EmailAccountService.cs
+++ b/src/Business/Grand.Business.Messages/Services/EmailAccountService.cs
@@ -153,7 +153,6 @@ namespace Grand.Business.Messages.Services
return await _cacheBase.GetAsync(CacheKey.EMAILACCOUNT_ALL_KEY, async () =>
{
var query = from ea in _emailAccountRepository.Table
- orderby ea.Id
select ea;
return await Task.FromResult(query.ToList());
});
diff --git a/src/Business/Grand.Business.Storage/Services/PictureService.cs b/src/Business/Grand.Business.Storage/Services/PictureService.cs
index e8e31bbd4..22a98e275 100644
--- a/src/Business/Grand.Business.Storage/Services/PictureService.cs
+++ b/src/Business/Grand.Business.Storage/Services/PictureService.cs
@@ -564,7 +564,6 @@ namespace Grand.Business.Storage.Services
public virtual IPagedList<Picture> GetPictures(int pageIndex = 0, int pageSize = int.MaxValue)
{
var query = from p in _pictureRepository.Table
- orderby p.Id descending
select p;
var pictures = new PagedList<Picture>(query, pageIndex, pageSize);
return pictures;
diff --git a/src/Business/Grand.Business.System/Commands/Handlers/Security/InstallPermissionsCommandHandler.cs b/src/Business/Grand.Business.System/Commands/Handlers/Security/InstallPermissionsCommandHandler.cs
index 6a6d92549..8cf285646 100644
--- a/src/Business/Grand.Business.System/Commands/Handlers/Security/InstallPermissionsCommandHandler.cs
+++ b/src/Business/Grand.Business.System/Commands/Handlers/Security/InstallPermissionsCommandHandler.cs
@@ -2,7 +2,6 @@
using Grand.Business.Common.Interfaces.Directory;
using Grand.Business.Common.Interfaces.Localization;
using Grand.Business.Common.Interfaces.Security;
-using Grand.Business.Customers.Interfaces;
using Grand.Business.System.Commands.Models.Security;
using Grand.Domain.Customers;
using Grand.Domain.Permissions;
@@ -16,20 +15,17 @@ namespace Grand.Business.System.Commands.Handlers.Security
public class InstallPermissionsCommandHandler : IRequestHandler<InstallPermissionsCommand, bool>
{
private readonly IPermissionService _permissionService;
- private readonly ICustomerService _customerService;
private readonly IGroupService _groupService;
private readonly ITranslationService _translationService;
private readonly ILanguageService _languageService;
public InstallPermissionsCommandHandler(
IPermissionService permissionService,
- ICustomerService customerService,
IGroupService groupService,
ITranslationService translationService,
ILanguageService languageService)
{
_permissionService = permissionService;
- _customerService = customerService;
_groupService = groupService;
_translationService = translationService;
_languageService = languageService;
@@ -45,8 +41,7 @@ namespace Grand.Business.System.Commands.Handlers.Security
if (permission1 == null)
{
//new permission (install it)
- permission1 = new Permission
- {
+ permission1 = new Permission {
Name = permission.Name,
SystemName = permission.SystemName,
Area = permission.Area,
@@ -63,8 +58,7 @@ namespace Grand.Business.System.Commands.Handlers.Security
if (customerGroup == null)
{
//new role (save it)
- customerGroup = new CustomerGroup
- {
+ customerGroup = new CustomerGroup {
Name = defaultPermission.CustomerGroupSystemName,
Active = true,
SystemName = defaultPermission.CustomerGroupSystemName
diff --git a/src/Business/Grand.Business.System/Services/Installation/InstallationService.cs b/src/Business/Grand.Business.System/Services/Installation/InstallationService.cs
index 64d061b62..98bbad139 100644
--- a/src/Business/Grand.Business.System/Services/Installation/InstallationService.cs
+++ b/src/Business/Grand.Business.System/Services/Installation/InstallationService.cs
@@ -125,7 +125,7 @@ namespace Grand.Business.System.Services.Installation
private readonly IRepository<KnowledgebaseCategory> _knowledgebaseCategoryRepository;
private readonly IRepository<OrderTag> _orderTagRepository;
private readonly IRepository<OrderStatus> _orderStatusRepository;
-
+ private readonly IRepository<PopupActive> _popupActiveRepository;
private readonly IWebHostEnvironment _hostingEnvironment;
private readonly IServiceProvider _serviceProvider;
@@ -218,6 +218,8 @@ namespace Grand.Business.System.Services.Installation
_popupArchive = new MongoRepository<PopupArchive>(dataProviderSettings.ConnectionString);
_orderTagRepository = new MongoRepository<OrderTag>(dataProviderSettings.ConnectionString);
_orderStatusRepository = new MongoRepository<OrderStatus>(dataProviderSettings.ConnectionString);
+ _popupActiveRepository = new MongoRepository<PopupActive>(dataProviderSettings.ConnectionString);
+
_hostingEnvironment = serviceProvider.GetRequiredService<IWebHostEnvironment>();
_serviceProvider = serviceProvider;
@@ -263,6 +265,10 @@ namespace Grand.Business.System.Services.Installation
//Language
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");
+ await dbContext.CreateIndex(_languageRepository, OrderBuilder<Language>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder");
+
+ //Currency
+ await dbContext.CreateIndex(_currencyRepository, OrderBuilder<Currency>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder");
//customer
await dbContext.CreateIndex(_customerRepository, OrderBuilder<Customer>.Create().Descending(x => x.CreatedOnUtc).Ascending(x => x.Deleted), "CreatedOnUtc_1");
@@ -270,6 +276,11 @@ namespace Grand.Business.System.Services.Installation
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");
+ await dbContext.CreateIndex(_customerGroupRepository, OrderBuilder<CustomerGroup>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder");
+ await dbContext.CreateIndex(_customerGroupRepository, OrderBuilder<CustomerGroup>.Create().Ascending(x => x.Name), "Name");
+
+ await dbContext.CreateIndex(_vendorRepository, OrderBuilder<Vendor>.Create().Ascending(x => x.DisplayOrder).Ascending(x => x.Name), "DisplayOrder_Name");
+
//product customer group
await dbContext.CreateIndex(_customerGroupProductRepository, OrderBuilder<CustomerGroupProduct>.Create().Ascending(x => x.CustomerGroupId).Ascending(x => x.DisplayOrder), "CustomerGroupId_DisplayOrder");
@@ -299,17 +310,21 @@ namespace Grand.Business.System.Services.Installation
await dbContext.CreateIndex(_checkoutAttributeRepository, OrderBuilder<CheckoutAttribute>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder");
//category
- 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.Published).Ascending(x => x.ShowOnHomePage).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");
+ await dbContext.CreateIndex(_categoryRepository, OrderBuilder<Category>.Create().Ascending(x => x.SearchBoxDisplayOrder), "SearchBoxDisplayOrder");
+ await dbContext.CreateIndex(_categoryRepository, OrderBuilder<Category>.Create().Ascending(x => x.ParentCategoryId).Ascending(x => x.DisplayOrder).Ascending(x => x.Name), "ParentCategoryId_1_DisplayOrder_1_Name_1");
+
+ await dbContext.CreateIndex(_categoryRepository, OrderBuilder<Category>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder_1");
//collection
- await dbContext.CreateIndex(_collectionRepository, OrderBuilder<Collection>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder_1");
+ await dbContext.CreateIndex(_collectionRepository, OrderBuilder<Collection>.Create().Ascending(x => x.DisplayOrder).Ascending(x => x.Name), "DisplayOrder_Name");
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 dbContext.CreateIndex(_brandRepository, OrderBuilder<Brand>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder_1");
+ await dbContext.CreateIndex(_brandRepository, OrderBuilder<Brand>.Create().Ascending(x => x.DisplayOrder).Ascending(x => x.Name), "DisplayOrder_Name");
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");
@@ -333,6 +348,8 @@ namespace Grand.Business.System.Services.Installation
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");
+ await dbContext.CreateIndex(_productRepository, OrderBuilder<Product>.Create().Ascending(x => x.DisplayOrder).Ascending(x => x.Name), "DisplayOrder_Name");
+
//productreseration
await dbContext.CreateIndex(_productReservationRepository, OrderBuilder<ProductReservation>.Create().Ascending(x => x.ProductId).Ascending(x => x.Date), "ProductReservation");
@@ -350,8 +367,10 @@ namespace Grand.Business.System.Services.Installation
await dbContext.CreateIndex(_productalsopurchasedRepository, OrderBuilder<ProductAlsoPurchased>.Create().Ascending(x => x.ProductId), "ProductId");
//url record
- 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.Slug).Ascending(x => x.IsActive), "SlugActive");
+ await dbContext.CreateIndex(_entityUrlRepository, OrderBuilder<EntityUrl>.Create().Ascending(x => x.Slug).Ascending(x => x.Slug), "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");
+ await dbContext.CreateIndex(_entityUrlRepository, OrderBuilder<EntityUrl>.Create().Ascending(x => x.IsActive), "IsActive");
//message template
await dbContext.CreateIndex(_messageTemplateRepository, OrderBuilder<MessageTemplate>.Create().Ascending(x => x.Name), "Name");
@@ -414,6 +433,7 @@ namespace Grand.Business.System.Services.Installation
//permision
await dbContext.CreateIndex(_permissionRepository, OrderBuilder<Permission>.Create().Ascending(x => x.SystemName), "SystemName", true);
+ await dbContext.CreateIndex(_permissionRepository, OrderBuilder<Permission>.Create().Ascending(x => x.Name), "Name", false);
await dbContext.CreateIndex(_permissionAction, OrderBuilder<PermissionAction>.Create().Ascending(x => x.SystemName), "SystemName");
@@ -434,9 +454,26 @@ namespace Grand.Business.System.Services.Installation
//banner
await dbContext.CreateIndex(_popupArchive, OrderBuilder<PopupArchive>.Create().Ascending(x => x.CustomerActionId), "CustomerActionId");
+ await dbContext.CreateIndex(_popupActiveRepository, OrderBuilder<PopupActive>.Create().Ascending(x => x.CreatedOnUtc), "CreatedOnUtc");
//customer reminder
await dbContext.CreateIndex(_customerReminderHistoryRepository, OrderBuilder<CustomerReminderHistory>.Create().Ascending(x => x.CustomerId).Ascending(x => x.CustomerReminderId), "CustomerId");
+
+ //page
+ await dbContext.CreateIndex(_pageRepository, OrderBuilder<Page>.Create().Ascending(x => x.DisplayOrder).Ascending(x => x.SystemName), "DisplayOrder_SystemName");
+
+ //customeractivity
+ await dbContext.CreateIndex(_activityLogTypeRepository, OrderBuilder<ActivityLogType>.Create().Ascending(x => x.Name), "Name");
+
+ //warehouse
+ await dbContext.CreateIndex(_warehouseRepository, OrderBuilder<Warehouse>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder");
+
+ //order status
+ await dbContext.CreateIndex(_orderStatusRepository, OrderBuilder<OrderStatus>.Create().Ascending(x => x.DisplayOrder), "DisplayOrder");
+
+ //country
+ await dbContext.CreateIndex(_countryRepository, OrderBuilder<Country>.Create().Ascending(x => x.DisplayOrder).Ascending(x => x.Name), "DisplayOrder_Name");
+
}
private async Task CreateTables(string local, bool skipCreateIndex)
diff --git a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
index f2584da5e..5629a2e78 100644
--- a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
+++ b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
@@ -287,14 +287,12 @@ namespace Grand.Web.Common.Infrastructure
public static void AddGrandHealthChecks(this IServiceCollection services)
{
var connection = DataSettingsManager.LoadSettings();
- if (connection.DbProvider == DbProvider.MongoDB)
- {
- var hcBuilder = services.AddHealthChecks();
- hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy());
- hcBuilder.AddMongoDb(connection.ConnectionString,
- name: "mongodb-check",
- tags: new string[] { "mongodb" });
- }
+ var hcBuilder = services.AddHealthChecks();
+ hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy());
+ hcBuilder.AddMongoDb(connection.ConnectionString,
+ name: "mongodb-check",
+ tags: new string[] { "mongodb" });
+
}
public static void AddHtmlMinification(this IServiceCollection services, IConfiguration configuration)