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.

Change the structure mongodb files

KrzysztofPajak01228fa35966
diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetBrandQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetBrandQueryHandler.cs
index 9650494c8..ae1403640 100644
--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetBrandQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Catalog/GetBrandQueryHandler.cs
@@ -10,15 +10,15 @@ namespace Grand.Api.Queries.Handlers.Common
{
public class GetBrandQueryHandler : IRequestHandler<GetQuery<BrandDto>, IQueryable<BrandDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetBrandQueryHandler(IMongoDBContext mongoDBContext)
+ public GetBrandQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<BrandDto>> Handle(GetQuery<BrandDto> request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<BrandDto>(typeof(Domain.Catalog.Brand).Name);
+ var query = _dbContext.Table<BrandDto>(typeof(Domain.Catalog.Brand).Name);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetCategoryQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetCategoryQueryHandler.cs
index 334835748..841aa48b2 100644
--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetCategoryQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Catalog/GetCategoryQueryHandler.cs
@@ -10,15 +10,15 @@ namespace Grand.Api.Queries.Handlers.Common
{
public class GetCategoryQueryHandler : IRequestHandler<GetQuery<CategoryDto>, IQueryable<CategoryDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetCategoryQueryHandler(IMongoDBContext mongoDBContext)
+ public GetCategoryQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<CategoryDto>> Handle(GetQuery<CategoryDto> request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<CategoryDto>(typeof(Domain.Catalog.Category).Name);
+ var query = _dbContext.Table<CategoryDto>(typeof(Domain.Catalog.Category).Name);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetCollectionQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetCollectionQueryHandler.cs
index 2fda566d7..84e3fa513 100644
--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetCollectionQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Catalog/GetCollectionQueryHandler.cs
@@ -10,16 +10,16 @@ namespace Grand.Api.Queries.Handlers.Common
{
public class GetCollectionQueryHandler : IRequestHandler<GetQuery<CollectionDto>, IQueryable<CollectionDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetCollectionQueryHandler(IMongoDBContext mongoDBContext)
+ public GetCollectionQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<CollectionDto>> Handle(GetQuery<CollectionDto> request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<CollectionDto>(typeof(Domain.Catalog.Collection).Name);
+ var query = _dbContext.Table<CollectionDto>(typeof(Domain.Catalog.Collection).Name);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductAttributeQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductAttributeQueryHandler.cs
index eedab4047..7f13b9013 100644
--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductAttributeQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductAttributeQueryHandler.cs
@@ -10,15 +10,15 @@ namespace Grand.Api.Queries.Handlers.Common
{
public class GetProductAttributeQueryHandler : IRequestHandler<GetQuery<ProductAttributeDto>, IQueryable<ProductAttributeDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetProductAttributeQueryHandler(IMongoDBContext mongoDBContext)
+ public GetProductAttributeQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<ProductAttributeDto>> Handle(GetQuery<ProductAttributeDto> request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<ProductAttributeDto>(typeof(Domain.Catalog.ProductAttribute).Name);
+ var query = _dbContext.Table<ProductAttributeDto>(typeof(Domain.Catalog.ProductAttribute).Name);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductQueryHandler.cs
index 6ea110a68..5f8980c39 100644
--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Catalog/GetProductQueryHandler.cs
@@ -10,16 +10,16 @@ namespace Grand.Api.Queries.Handlers.Common
{
public class GetProductQueryHandler : IRequestHandler<GetQuery<ProductDto>, IQueryable<ProductDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetProductQueryHandler(IMongoDBContext mongoDBContext)
+ public GetProductQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<ProductDto>> Handle(GetQuery<ProductDto> request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<ProductDto>(typeof(Domain.Catalog.Product).Name);
+ var query = _dbContext.Table<ProductDto>(typeof(Domain.Catalog.Product).Name);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/API/Grand.Api/Queries/Handlers/Catalog/GetSpecificationAttributeQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Catalog/GetSpecificationAttributeQueryHandler.cs
index 21b3853ca..c787ac028 100644
--- a/src/API/Grand.Api/Queries/Handlers/Catalog/GetSpecificationAttributeQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Catalog/GetSpecificationAttributeQueryHandler.cs
@@ -10,15 +10,15 @@ namespace Grand.Api.Queries.Handlers.Common
{
public class GetSpecificationAttributeQueryHandler : IRequestHandler<GetQuery<SpecificationAttributeDto>, IQueryable<SpecificationAttributeDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetSpecificationAttributeQueryHandler(IMongoDBContext mongoDBContext)
+ public GetSpecificationAttributeQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<SpecificationAttributeDto>> Handle(GetQuery<SpecificationAttributeDto> request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<SpecificationAttributeDto>(typeof(Domain.Catalog.SpecificationAttribute).Name);
+ var query = _dbContext.Table<SpecificationAttributeDto>(typeof(Domain.Catalog.SpecificationAttribute).Name);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetCountryQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetCountryQueryHandler.cs
index b99c70d0f..b8237e19d 100644
--- a/src/API/Grand.Api/Queries/Handlers/Common/GetCountryQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Common/GetCountryQueryHandler.cs
@@ -10,15 +10,15 @@ namespace Grand.Api.Queries.Handlers.Common
{
public class GetCountryQueryHandler : IRequestHandler<GetQuery<CountryDto>, IQueryable<CountryDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetCountryQueryHandler(IMongoDBContext mongoDBContext)
+ public GetCountryQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<CountryDto>> Handle(GetQuery<CountryDto> request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<CountryDto>(typeof(Domain.Directory.Country).Name);
+ var query = _dbContext.Table<CountryDto>(typeof(Domain.Directory.Country).Name);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetCurrencyQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetCurrencyQueryHandler.cs
index 685e162d8..b5a2729e9 100644
--- a/src/API/Grand.Api/Queries/Handlers/Common/GetCurrencyQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Common/GetCurrencyQueryHandler.cs
@@ -10,15 +10,15 @@ namespace Grand.Api.Queries.Handlers.Common
{
public class GetCurrencyQueryHandler : IRequestHandler<GetQuery<CurrencyDto>, IQueryable<CurrencyDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetCurrencyQueryHandler(IMongoDBContext mongoDBContext)
+ public GetCurrencyQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<CurrencyDto>> Handle(GetQuery<CurrencyDto> request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<CurrencyDto>(typeof(Domain.Directory.Currency).Name);
+ var query = _dbContext.Table<CurrencyDto>(typeof(Domain.Directory.Currency).Name);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetLanguageQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetLanguageQueryHandler.cs
index bc11ddbeb..a7dc1119f 100644
--- a/src/API/Grand.Api/Queries/Handlers/Common/GetLanguageQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Common/GetLanguageQueryHandler.cs
@@ -10,15 +10,15 @@ namespace Grand.Api.Queries.Handlers.Common
{
public class GetLanguageQueryHandler : IRequestHandler<GetQuery<LanguageDto>, IQueryable<LanguageDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetLanguageQueryHandler(IMongoDBContext mongoDBContext)
+ public GetLanguageQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<LanguageDto>> Handle(GetQuery<LanguageDto> request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<LanguageDto>(typeof(Domain.Localization.Language).Name);
+ var query = _dbContext.Table<LanguageDto>(typeof(Domain.Localization.Language).Name);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetLayoutQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetLayoutQueryHandler.cs
index f4d51d88e..1b4b4ff0e 100644
--- a/src/API/Grand.Api/Queries/Handlers/Common/GetLayoutQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Common/GetLayoutQueryHandler.cs
@@ -10,16 +10,16 @@ namespace Grand.Api.Queries.Handlers.Common
{
public class GetLayoutQueryHandler : IRequestHandler<GetLayoutQuery, IQueryable<LayoutDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetLayoutQueryHandler(IMongoDBContext mongoDBContext)
+ public GetLayoutQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<LayoutDto>> Handle(GetLayoutQuery request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<LayoutDto>(request.LayoutName);
+ var query = _dbContext.Table<LayoutDto>(request.LayoutName);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetPictureByIdQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetPictureByIdQueryHandler.cs
index bc8af818e..a7828f628 100644
--- a/src/API/Grand.Api/Queries/Handlers/Common/GetPictureByIdQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Common/GetPictureByIdQueryHandler.cs
@@ -10,16 +10,16 @@ namespace Grand.Api.Queries.Handlers.Common
{
public class GetPictureByIdQueryHandler : IRequestHandler<GetPictureByIdQuery, PictureDto>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetPictureByIdQueryHandler(IMongoDBContext mongoDBContext)
+ public GetPictureByIdQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<PictureDto> Handle(GetPictureByIdQuery request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<PictureDto>(typeof(Domain.Media.Picture).Name);
+ var query = _dbContext.Table<PictureDto>(typeof(Domain.Media.Picture).Name);
return await Task.FromResult(query.Where(x => x.Id == request.Id).FirstOrDefault());
}
}
diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetStateProvinceQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetStateProvinceQueryHandler.cs
index c90e1ccac..f73a3680a 100644
--- a/src/API/Grand.Api/Queries/Handlers/Common/GetStateProvinceQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Common/GetStateProvinceQueryHandler.cs
@@ -10,15 +10,15 @@ namespace Grand.Api.Queries.Handlers.Common
{
public class GetStateProvinceQueryHandler : IRequestHandler<GetQuery<StateProvinceDto>, IQueryable<StateProvinceDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetStateProvinceQueryHandler(IMongoDBContext mongoDBContext)
+ public GetStateProvinceQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<StateProvinceDto>> Handle(GetQuery<StateProvinceDto> request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<StateProvinceDto>(typeof(Domain.Directory.StateProvince).Name);
+ var query = _dbContext.Table<StateProvinceDto>(typeof(Domain.Directory.StateProvince).Name);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetStoreQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetStoreQueryHandler.cs
index c5deef917..c2986d6ce 100644
--- a/src/API/Grand.Api/Queries/Handlers/Common/GetStoreQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Common/GetStoreQueryHandler.cs
@@ -10,15 +10,15 @@ namespace Grand.Api.Queries.Handlers.Common
{
public class GetStoreQueryHandler : IRequestHandler<GetQuery<StoreDto>, IQueryable<StoreDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetStoreQueryHandler(IMongoDBContext mongoDBContext)
+ public GetStoreQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<StoreDto>> Handle(GetQuery<StoreDto> request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<StoreDto>(typeof(Domain.Stores.Store).Name);
+ var query = _dbContext.Table<StoreDto>(typeof(Domain.Stores.Store).Name);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/API/Grand.Api/Queries/Handlers/Customers/GetCustomerGroupQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Customers/GetCustomerGroupQueryHandler.cs
index f9393e249..9d21cde69 100644
--- a/src/API/Grand.Api/Queries/Handlers/Customers/GetCustomerGroupQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Customers/GetCustomerGroupQueryHandler.cs
@@ -10,15 +10,15 @@ namespace Grand.Api.Queries.Handlers.Customers
{
public class GetCustomerGroupQueryHandler : IRequestHandler<GetQuery<CustomerGroupDto>, IQueryable<CustomerGroupDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetCustomerGroupQueryHandler(IMongoDBContext mongoDBContext)
+ public GetCustomerGroupQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<CustomerGroupDto>> Handle(GetQuery<CustomerGroupDto> request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<CustomerGroupDto>(typeof(Domain.Customers.CustomerGroup).Name);
+ var query = _dbContext.Table<CustomerGroupDto>(typeof(Domain.Customers.CustomerGroup).Name);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/API/Grand.Api/Queries/Handlers/Customers/GetVendorQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Customers/GetVendorQueryHandler.cs
index 26aa51d11..1ffc4776b 100644
--- a/src/API/Grand.Api/Queries/Handlers/Customers/GetVendorQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Customers/GetVendorQueryHandler.cs
@@ -10,15 +10,15 @@ namespace Grand.Api.Queries.Handlers.Customers
{
public class GetVendorQueryHandler : IRequestHandler<GetQuery<VendorDto>, IQueryable<VendorDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetVendorQueryHandler(IMongoDBContext mongoDBContext)
+ public GetVendorQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<VendorDto>> Handle(GetQuery<VendorDto> request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<VendorDto>(typeof(Domain.Vendors.Vendor).Name);
+ var query = _dbContext.Table<VendorDto>(typeof(Domain.Vendors.Vendor).Name);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/API/Grand.Api/Queries/Handlers/Shipping/GetDeliveryDateQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Shipping/GetDeliveryDateQueryHandler.cs
index dbd45901c..586b03639 100644
--- a/src/API/Grand.Api/Queries/Handlers/Shipping/GetDeliveryDateQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Shipping/GetDeliveryDateQueryHandler.cs
@@ -10,15 +10,15 @@ namespace Grand.Api.Queries.Handlers.Shipping
{
public class GetDeliveryDateQueryHandler : IRequestHandler<GetQuery<DeliveryDateDto>, IQueryable<DeliveryDateDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetDeliveryDateQueryHandler(IMongoDBContext mongoDBContext)
+ public GetDeliveryDateQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<DeliveryDateDto>> Handle(GetQuery<DeliveryDateDto> request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<DeliveryDateDto>(typeof(Domain.Shipping.DeliveryDate).Name);
+ var query = _dbContext.Table<DeliveryDateDto>(typeof(Domain.Shipping.DeliveryDate).Name);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/API/Grand.Api/Queries/Handlers/Shipping/GetPickupPointQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Shipping/GetPickupPointQueryHandler.cs
index 8d76e8265..afe882775 100644
--- a/src/API/Grand.Api/Queries/Handlers/Shipping/GetPickupPointQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Shipping/GetPickupPointQueryHandler.cs
@@ -10,15 +10,15 @@ namespace Grand.Api.Queries.Handlers.Shipping
{
public class GetPickupPointQueryHandler : IRequestHandler<GetQuery<PickupPointDto>, IQueryable<PickupPointDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetPickupPointQueryHandler(IMongoDBContext mongoDBContext)
+ public GetPickupPointQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<PickupPointDto>> Handle(GetQuery<PickupPointDto> request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<PickupPointDto>(typeof(Domain.Shipping.PickupPoint).Name);
+ var query = _dbContext.Table<PickupPointDto>(typeof(Domain.Shipping.PickupPoint).Name);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/API/Grand.Api/Queries/Handlers/Shipping/GetShippingMethodQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Shipping/GetShippingMethodQueryHandler.cs
index d33acb0a3..bbf1b5974 100644
--- a/src/API/Grand.Api/Queries/Handlers/Shipping/GetShippingMethodQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Shipping/GetShippingMethodQueryHandler.cs
@@ -10,15 +10,15 @@ namespace Grand.Api.Queries.Handlers.Shipping
{
public class GetShippingMethodQueryHandler : IRequestHandler<GetQuery<ShippingMethodDto>, IQueryable<ShippingMethodDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetShippingMethodQueryHandler(IMongoDBContext mongoDBContext)
+ public GetShippingMethodQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<ShippingMethodDto>> Handle(GetQuery<ShippingMethodDto> request, CancellationToken cancellationToken)
{
- var shippingMethod = _mongoDBContext.Table<ShippingMethodDto>(typeof(Domain.Shipping.ShippingMethod).Name);
+ var shippingMethod = _dbContext.Table<ShippingMethodDto>(typeof(Domain.Shipping.ShippingMethod).Name);
if (string.IsNullOrEmpty(request.Id))
return shippingMethod;
diff --git a/src/API/Grand.Api/Queries/Handlers/Shipping/GetWarehouseQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Shipping/GetWarehouseQueryHandler.cs
index 620b6303d..a58f945c4 100644
--- a/src/API/Grand.Api/Queries/Handlers/Shipping/GetWarehouseQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Shipping/GetWarehouseQueryHandler.cs
@@ -10,15 +10,15 @@ namespace Grand.Api.Queries.Handlers.Shipping
{
public class GetWarehouseQueryHandler : IRequestHandler<GetQuery<WarehouseDto>, IQueryable<WarehouseDto>>
{
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
- public GetWarehouseQueryHandler(IMongoDBContext mongoDBContext)
+ public GetWarehouseQueryHandler(IDatabaseContext dbContext)
{
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task<IQueryable<WarehouseDto>> Handle(GetQuery<WarehouseDto> request, CancellationToken cancellationToken)
{
- var query = _mongoDBContext.Table<WarehouseDto>(typeof(Domain.Shipping.Warehouse).Name);
+ var query = _dbContext.Table<WarehouseDto>(typeof(Domain.Shipping.Warehouse).Name);
if (string.IsNullOrEmpty(request.Id))
return query;
diff --git a/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.cs b/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.cs
index fadff600a..236a4b9dc 100644
--- a/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.cs
+++ b/src/Business/Grand.Business.Common/Services/Pdf/WkPdfService.cs
@@ -26,16 +26,16 @@ namespace Grand.Business.Common.Services.Pdf
private readonly IViewRenderService _viewRenderService;
private readonly ILanguageService _languageService;
private readonly IRepository<Download> _downloadRepository;
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
public WkPdfService(IGeneratePdf generatePdf, IViewRenderService viewRenderService, IRepository<Download> downloadRepository,
- ILanguageService languageService, IMongoDBContext mongoDBContext)
+ ILanguageService languageService, IDatabaseContext dbContext)
{
_generatePdf = generatePdf;
_viewRenderService = viewRenderService;
_languageService = languageService;
_downloadRepository = downloadRepository;
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
}
public async Task PrintOrdersToPdf(Stream stream, IList<Order> orders, string languageId = "", string vendorId = "")
@@ -122,7 +122,7 @@ namespace Grand.Business.Common.Services.Pdf
ContentType = "application/pdf",
};
- download.DownloadObjectId = await _mongoDBContext.GridFSBucketUploadFromBytesAsync(download.Filename, ms.ToArray());
+ download.DownloadObjectId = await _dbContext.GridFSBucketUploadFromBytesAsync(download.Filename, ms.ToArray());
await _downloadRepository.InsertAsync(download);
//TODO
diff --git a/src/Business/Grand.Business.Storage/Services/DownloadService.cs b/src/Business/Grand.Business.Storage/Services/DownloadService.cs
index 8170c1d40..0fb297c63 100644
--- a/src/Business/Grand.Business.Storage/Services/DownloadService.cs
+++ b/src/Business/Grand.Business.Storage/Services/DownloadService.cs
@@ -17,7 +17,7 @@ namespace Grand.Business.Storage.Services
#region Fields
private readonly IRepository<Download> _downloadRepository;
- private readonly IMongoDBContext _mongoDBContext;
+ private readonly IDatabaseContext _dbContext;
private readonly IMediator _mediator;
#endregion
@@ -28,14 +28,14 @@ namespace Grand.Business.Storage.Services
/// Ctor
/// </summary>
/// <param name="downloadRepository">Download repository</param>
- /// <param name="mongoDBContext">DbContext</param>
+ /// <param name="dbContext">DbContext</param>
/// <param name="mediator">Mediator</param>
public DownloadService(IRepository<Download> downloadRepository,
- IMongoDBContext mongoDBContext,
+ IDatabaseContext dbContext,
IMediator mediator)
{
_downloadRepository = downloadRepository;
- _mongoDBContext = mongoDBContext;
+ _dbContext = dbContext;
_mediator = mediator;
}
@@ -62,7 +62,7 @@ namespace Grand.Business.Storage.Services
protected virtual async Task<byte[]> DownloadAsBytes(string objectId)
{
- var binary = await _mongoDBContext.GridFSBucketDownload(objectId);
+ var binary = await _dbContext.GridFSBucketDownload(objectId);
return binary;
}
/// <summary>
@@ -96,7 +96,7 @@ namespace Grand.Business.Storage.Services
throw new ArgumentNullException(nameof(download));
if (!download.UseDownloadUrl)
{
- download.DownloadObjectId = await _mongoDBContext.GridFSBucketUploadFromBytesAsync(download.Filename, download.DownloadBinary);
+ download.DownloadObjectId = await _dbContext.GridFSBucketUploadFromBytesAsync(download.Filename, download.DownloadBinary);
}
download.DownloadBinary = null;
diff --git a/src/Business/Grand.Business.System/Services/Installation/InstallationService.cs b/src/Business/Grand.Business.System/Services/Installation/InstallationService.cs
index 1c809d127..fbabd5d2d 100644
--- a/src/Business/Grand.Business.System/Services/Installation/InstallationService.cs
+++ b/src/Business/Grand.Business.System/Services/Installation/InstallationService.cs
@@ -11,6 +11,7 @@ using Grand.Domain.Common;
using Grand.Domain.Configuration;
using Grand.Domain.Customers;
using Grand.Domain.Data;
+using Grand.Domain.Data.Mongo;
using Grand.Domain.Directory;
using Grand.Domain.Discounts;
using Grand.Domain.Knowledgebase;
@@ -44,87 +45,87 @@ namespace Grand.Business.System.Services.Installation
{
#region Fields
- 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 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 IWebHostEnvironment _hostingEnvironment;
private readonly IServiceProvider _serviceProvider;
@@ -137,87 +138,87 @@ namespace Grand.Business.System.Services.Installation
{
var dataProviderSettings = DataSettingsManager.LoadSettings(reloadSettings: true);
- _versionRepository = new Repository<GrandNodeVersion>(dataProviderSettings.ConnectionString);
- _adminRepository = new Repository<AdminSiteMap>(dataProviderSettings.ConnectionString);
- _bidRepository = new Repository<Bid>(dataProviderSettings.ConnectionString);
- _affiliateRepository = new Repository<Affiliate>(dataProviderSettings.ConnectionString);
- _campaignHistoryRepository = new Repository<CampaignHistory>(dataProviderSettings.ConnectionString);
- _orderRepository = new Repository<Order>(dataProviderSettings.ConnectionString);
- _orderNoteRepository = new Repository<OrderNote>(dataProviderSettings.ConnectionString);
- _storeRepository = new Repository<Store>(dataProviderSettings.ConnectionString);
- _measureDimensionRepository = new Repository<MeasureDimension>(dataProviderSettings.ConnectionString);
- _measureWeightRepository = new Repository<MeasureWeight>(dataProviderSettings.ConnectionString);
- _measureUnitRepository = new Repository<MeasureUnit>(dataProviderSettings.ConnectionString);
- _taxCategoryRepository = new Repository<TaxCategory>(dataProviderSettings.ConnectionString);
- _languageRepository = new Repository<Language>(dataProviderSettings.ConnectionString);
- _lsrRepository = new Repository<TranslationResource>(dataProviderSettings.ConnectionString);
- _logRepository = new Repository<Log>(dataProviderSettings.ConnectionString);
- _currencyRepository = new Repository<Currency>(dataProviderSettings.ConnectionString);
- _customerRepository = new Repository<Customer>(dataProviderSettings.ConnectionString);
- _customerGroupRepository = new Repository<CustomerGroup>(dataProviderSettings.ConnectionString);
- _customerProductRepository = new Repository<CustomerProduct>(dataProviderSettings.ConnectionString);
- _customerProductPriceRepository = new Repository<CustomerProductPrice>(dataProviderSettings.ConnectionString);
- _customerGroupProductRepository = new Repository<CustomerGroupProduct>(dataProviderSettings.ConnectionString);
- _customerTagProductRepository = new Repository<CustomerTagProduct>(dataProviderSettings.ConnectionString);
- _customerHistoryPasswordRepository = new Repository<CustomerHistoryPassword>(dataProviderSettings.ConnectionString);
- _customerNoteRepository = new Repository<CustomerNote>(dataProviderSettings.ConnectionString);
- _userapiRepository = new Repository<UserApi>(dataProviderSettings.ConnectionString);
- _specificationAttributeRepository = new Repository<SpecificationAttribute>(dataProviderSettings.ConnectionString);
- _checkoutAttributeRepository = new Repository<CheckoutAttribute>(dataProviderSettings.ConnectionString);
- _productAttributeRepository = new Repository<ProductAttribute>(dataProviderSettings.ConnectionString);
- _categoryRepository = new Repository<Category>(dataProviderSettings.ConnectionString);
- _brandRepository = new Repository<Brand>(dataProviderSettings.ConnectionString);
- _collectionRepository = new Repository<Collection>(dataProviderSettings.ConnectionString);
- _productRepository = new Repository<Product>(dataProviderSettings.ConnectionString);
- _productReservationRepository = new Repository<ProductReservation>(dataProviderSettings.ConnectionString);
- _productalsopurchasedRepository = new Repository<ProductAlsoPurchased>(dataProviderSettings.ConnectionString);
- _entityUrlRepository = new Repository<EntityUrl>(dataProviderSettings.ConnectionString);
- _emailAccountRepository = new Repository<EmailAccount>(dataProviderSettings.ConnectionString);
- _messageTemplateRepository = new Repository<MessageTemplate>(dataProviderSettings.ConnectionString);
- _countryRepository = new Repository<Country>(dataProviderSettings.ConnectionString);
- _discountRepository = new Repository<Discount>(dataProviderSettings.ConnectionString);
- _discountCouponRepository = new Repository<DiscountCoupon>(dataProviderSettings.ConnectionString);
- _blogPostRepository = new Repository<BlogPost>(dataProviderSettings.ConnectionString);
- _pageRepository = new Repository<Page>(dataProviderSettings.ConnectionString);
- _productReviewRepository = new Repository<ProductReview>(dataProviderSettings.ConnectionString);
- _newsItemRepository = new Repository<NewsItem>(dataProviderSettings.ConnectionString);
- _newslettersubscriptionRepository = new Repository<NewsLetterSubscription>(dataProviderSettings.ConnectionString);
- _shippingMethodRepository = new Repository<ShippingMethod>(dataProviderSettings.ConnectionString);
- _deliveryDateRepository = new Repository<DeliveryDate>(dataProviderSettings.ConnectionString);
- _activityLogTypeRepository = new Repository<ActivityLogType>(dataProviderSettings.ConnectionString);
- _productTagRepository = new Repository<ProductTag>(dataProviderSettings.ConnectionString);
- _productLayoutRepository = new Repository<ProductLayout>(dataProviderSettings.ConnectionString);
- _recentlyViewedProductRepository = new Repository<RecentlyViewedProduct>(dataProviderSettings.ConnectionString);
- _categoryLayoutRepository = new Repository<CategoryLayout>(dataProviderSettings.ConnectionString);
- _brandLayoutRepository = new Repository<BrandLayout>(dataProviderSettings.ConnectionString);
- _collectionLayoutRepository = new Repository<CollectionLayout>(dataProviderSettings.ConnectionString);
- _pageLayoutRepository = new Repository<PageLayout>(dataProviderSettings.ConnectionString);
- _scheduleTaskRepository = new Repository<ScheduleTask>(dataProviderSettings.ConnectionString);
- _merchandiseReturnRepository = new Repository<MerchandiseReturn>(dataProviderSettings.ConnectionString);
- _merchandiseReturnNoteRepository = new Repository<MerchandiseReturnNote>(dataProviderSettings.ConnectionString);
- _loyaltypointshistoryRepository = new Repository<LoyaltyPointsHistory>(dataProviderSettings.ConnectionString);
- _searchtermRepository = new Repository<SearchTerm>(dataProviderSettings.ConnectionString);
- _settingRepository = new Repository<Setting>(dataProviderSettings.ConnectionString);
- _shipmentRepository = new Repository<Shipment>(dataProviderSettings.ConnectionString);
- _warehouseRepository = new Repository<Warehouse>(dataProviderSettings.ConnectionString);
- _pickupPointsRepository = new Repository<PickupPoint>(dataProviderSettings.ConnectionString);
- _permissionRepository = new Repository<Permission>(dataProviderSettings.ConnectionString);
- _permissionAction = new Repository<PermissionAction>(dataProviderSettings.ConnectionString);
- _vendorRepository = new Repository<Vendor>(dataProviderSettings.ConnectionString);
- _externalAuthenticationRepository = new Repository<ExternalAuthentication>(dataProviderSettings.ConnectionString);
- _discountusageRepository = new Repository<DiscountUsageHistory>(dataProviderSettings.ConnectionString);
- _merchandiseReturnReasonRepository = new Repository<MerchandiseReturnReason>(dataProviderSettings.ConnectionString);
- _contactUsRepository = new Repository<ContactUs>(dataProviderSettings.ConnectionString);
- _merchandiseReturnActionRepository = new Repository<MerchandiseReturnAction>(dataProviderSettings.ConnectionString);
- _customerAction = new Repository<CustomerAction>(dataProviderSettings.ConnectionString);
- _customerActionType = new Repository<CustomerActionType>(dataProviderSettings.ConnectionString);
- _customerActionHistory = new Repository<CustomerActionHistory>(dataProviderSettings.ConnectionString);
- _customerReminderHistoryRepository = new Repository<CustomerReminderHistory>(dataProviderSettings.ConnectionString);
- _knowledgebaseArticleRepository = new Repository<KnowledgebaseArticle>(dataProviderSettings.ConnectionString);
- _knowledgebaseCategoryRepository = new Repository<KnowledgebaseCategory>(dataProviderSettings.ConnectionString);
- _popupArchive = new Repository<PopupArchive>(dataProviderSettings.ConnectionString);
- _orderTagRepository = new Repository<OrderTag>(dataProviderSettings.ConnectionString);
- _orderStatusRepository = new Repository<OrderStatus>(dataProviderSettings.ConnectionString);
+ _versionRepository = new MongoRepository<GrandNodeVersion>(dataProviderSettings.ConnectionString);
+ _adminRepository = new MongoRepository<AdminSiteMap>(dataProviderSettings.ConnectionString);
+ _bidRepository = new MongoRepository<Bid>(dataProviderSettings.ConnectionString);
+ _affiliateRepository = new MongoRepository<Affiliate>(dataProviderSettings.ConnectionString);
+ _campaignHistoryRepository = new MongoRepository<CampaignHistory>(dataProviderSettings.ConnectionString);
+ _orderRepository = new MongoRepository<Order>(dataProviderSettings.ConnectionString);
+ _orderNoteRepository = new MongoRepository<OrderNote>(dataProviderSettings.ConnectionString);
+ _storeRepository = new MongoRepository<Store>(dataProviderSettings.ConnectionString);
+ _measureDimensionRepository = new MongoRepository<MeasureDimension>(dataProviderSettings.ConnectionString);
+ _measureWeightRepository = new MongoRepository<MeasureWeight>(dataProviderSettings.ConnectionString);
+ _measureUnitRepository = new MongoRepository<MeasureUnit>(dataProviderSettings.ConnectionString);
+ _taxCategoryRepository = new MongoRepository<TaxCategory>(dataProviderSettings.ConnectionString);
+ _languageRepository = new MongoRepository<Language>(dataProviderSettings.ConnectionString);
+ _lsrRepository = new MongoRepository<TranslationResource>(dataProviderSettings.ConnectionString);
+ _logRepository = new MongoRepository<Log>(dataProviderSettings.ConnectionString);
+ _currencyRepository = new MongoRepository<Currency>(dataProviderSettings.ConnectionString);
+ _customerRepository = new MongoRepository<Customer>(dataProviderSettings.ConnectionString);
+ _customerGroupRepository = new MongoRepository<CustomerGroup>(dataProviderSettings.ConnectionString);
+ _customerProductRepository = new MongoRepository<CustomerProduct>(dataProviderSettings.ConnectionString);
+ _customerProductPriceRepository = new MongoRepository<CustomerProductPrice>(dataProviderSettings.ConnectionString);
+ _customerGroupProductRepository = new MongoRepository<CustomerGroupProduct>(dataProviderSettings.ConnectionString);
+ _customerTagProductRepository = new MongoRepository<CustomerTagProduct>(dataProviderSettings.ConnectionString);
+ _customerHistoryPasswordRepository = new MongoRepository<CustomerHistoryPassword>(dataProviderSettings.ConnectionString);
+ _customerNoteRepository = new MongoRepository<CustomerNote>(dataProviderSettings.ConnectionString);
+ _userapiRepository = new MongoRepository<UserApi>(dataProviderSettings.ConnectionString);
+ _specificationAttributeRepository = new MongoRepository<SpecificationAttribute>(dataProviderSettings.ConnectionString);
+ _checkoutAttributeRepository = new MongoRepository<CheckoutAttribute>(dataProviderSettings.ConnectionString);
+ _productAttributeRepository = new MongoRepository<ProductAttribute>(dataProviderSettings.ConnectionString);
+ _categoryRepository = new MongoRepository<Category>(dataProviderSettings.ConnectionString);
+ _brandRepository = new MongoRepository<Brand>(dataProviderSettings.ConnectionString);
+ _collectionRepository = new MongoRepository<Collection>(dataProviderSettings.ConnectionString);
+ _productRepository = new MongoRepository<Product>(dataProviderSettings.ConnectionString);
+ _productReservationRepository = new MongoRepository<ProductReservation>(dataProviderSettings.ConnectionString);
+ _productalsopurchasedRepository = new MongoRepository<ProductAlsoPurchased>(dataProviderSettings.ConnectionString);
+ _entityUrlRepository = new MongoRepository<EntityUrl>(dataProviderSettings.ConnectionString);
+ _emailAccountRepository = new MongoRepository<EmailAccount>(dataProviderSettings.ConnectionString);
+ _messageTemplateRepository = new MongoRepository<MessageTemplate>(dataProviderSettings.ConnectionString);
+ _countryRepository = new MongoRepository<Country>(dataProviderSettings.ConnectionString);
+ _discountRepository = new MongoRepository<Discount>(dataProviderSettings.ConnectionString);
+ _discountCouponRepository = new MongoRepository<DiscountCoupon>(dataProviderSettings.ConnectionString);
+ _blogPostRepository = new MongoRepository<BlogPost>(dataProviderSettings.ConnectionString);
+ _pageRepository = new MongoRepository<Page>(dataProviderSettings.ConnectionString);
+ _productReviewRepository = new MongoRepository<ProductReview>(dataProviderSettings.ConnectionString);
+ _newsItemRepository = new MongoRepository<NewsItem>(dataProviderSettings.ConnectionString);
+ _newslettersubscriptionRepository = new MongoRepository<NewsLetterSubscription>(dataProviderSettings.ConnectionString);
+ _shippingMethodRepository = new MongoRepository<ShippingMethod>(dataProviderSettings.ConnectionString);
+ _deliveryDateRepository = new MongoRepository<DeliveryDate>(dataProviderSettings.ConnectionString);
+ _activityLogTypeRepository = new MongoRepository<ActivityLogType>(dataProviderSettings.ConnectionString);
+ _productTagRepository = new MongoRepository<ProductTag>(dataProviderSettings.ConnectionString);
+ _productLayoutRepository = new MongoRepository<ProductLayout>(dataProviderSettings.ConnectionString);
+ _recentlyViewedProductRepository = new MongoRepository<RecentlyViewedProduct>(dataProviderSettings.ConnectionString);
+ _categoryLayoutRepository = new MongoRepository<CategoryLayout>(dataProviderSettings.ConnectionString);
+ _brandLayoutRepository = new MongoRepository<BrandLayout>(dataProviderSettings.ConnectionString);
+ _collectionLayoutRepository = new MongoRepository<CollectionLayout>(dataProviderSettings.ConnectionString);
+ _pageLayoutRepository = new MongoRepository<PageLayout>(dataProviderSettings.ConnectionString);
+ _scheduleTaskRepository = new MongoRepository<ScheduleTask>(dataProviderSettings.ConnectionString);
+ _merchandiseReturnRepository = new MongoRepository<MerchandiseReturn>(dataProviderSettings.ConnectionString);
+ _merchandiseReturnNoteRepository = new MongoRepository<MerchandiseReturnNote>(dataProviderSettings.ConnectionString);
+ _loyaltypointshistoryRepository = new MongoRepository<LoyaltyPointsHistory>(dataProviderSettings.ConnectionString);
+ _searchtermRepository = new MongoRepository<SearchTerm>(dataProviderSettings.ConnectionString);
+ _settingRepository = new MongoRepository<Setting>(dataProviderSettings.ConnectionString);
+ _shipmentRepository = new MongoRepository<Shipment>(dataProviderSettings.ConnectionString);
+ _warehouseRepository = new MongoRepository<Warehouse>(dataProviderSettings.ConnectionString);
+ _pickupPointsRepository = new MongoRepository<PickupPoint>(dataProviderSettings.ConnectionString);
+ _permissionRepository = new MongoRepository<Permission>(dataProviderSettings.ConnectionString);
+ _permissionAction = new MongoRepository<PermissionAction>(dataProviderSettings.ConnectionString);
+ _vendorRepository = new MongoRepository<Vendor>(dataProviderSettings.ConnectionString);
+ _externalAuthenticationRepository = new MongoRepository<ExternalAuthentication>(dataProviderSettings.ConnectionString);
+ _discountusageRepository = new MongoRepository<DiscountUsageHistory>(dataProviderSettings.ConnectionString);
+ _merchandiseReturnReasonRepository = new MongoRepository<MerchandiseReturnReason>(dataProviderSettings.ConnectionString);
+ _contactUsRepository = new MongoRepository<ContactUs>(dataProviderSettings.ConnectionString);
+ _merchandiseReturnActionRepository = new MongoRepository<MerchandiseReturnAction>(dataProviderSettings.ConnectionString);
+ _customerAction = new MongoRepository<CustomerAction>(dataProviderSettings.ConnectionString);
+ _customerActionType = new MongoRepository<CustomerActionType>(dataProviderSettings.ConnectionString);
+ _customerActionHistory = new MongoRepository<CustomerActionHistory>(dataProviderSettings.ConnectionString);
+ _customerReminderHistoryRepository = new MongoRepository<CustomerReminderHistory>(dataProviderSettings.ConnectionString);
+ _knowledgebaseArticleRepository = new MongoRepository<KnowledgebaseArticle>(dataProviderSettings.ConnectionString);
+ _knowledgebaseCategoryRepository = new MongoRepository<KnowledgebaseCategory>(dataProviderSettings.ConnectionString);
+ _popupArchive = new MongoRepository<PopupArchive>(dataProviderSettings.ConnectionString);
+ _orderTagRepository = new MongoRepository<OrderTag>(dataProviderSettings.ConnectionString);
+ _orderStatusRepository = new MongoRepository<OrderStatus>(dataProviderSettings.ConnectionString);
_hostingEnvironment = serviceProvider.GetRequiredService<IWebHostEnvironment>();
_serviceProvider = serviceProvider;
@@ -457,14 +458,14 @@ namespace Grand.Business.System.Services.Installation
var mongourl = new MongoUrl(connectionString);
var databaseName = mongourl.DatabaseName;
var mongodb = new MongoClient(connectionString).GetDatabase(databaseName);
- var mongoDBContext = new MongoDBContext(mongodb);
+ var dbContext = new MongoDBContext(mongodb);
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 mongoDBContext.Database().CreateCollectionAsync(item.Name, options);
+ await dbContext.Database().CreateCollectionAsync(item.Name, options);
}
}
catch (Exception ex)
diff --git a/src/Core/Grand.Domain/Data/IDatabaseContext.cs b/src/Core/Grand.Domain/Data/IDatabaseContext.cs
new file mode 100644
index 000000000..0b2efc18c
--- /dev/null
+++ b/src/Core/Grand.Domain/Data/IDatabaseContext.cs
@@ -0,0 +1,13 @@
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace Grand.Domain.Data
+{
+ public interface IDatabaseContext
+ {
+ IQueryable<T> Table<T>(string collectionName);
+ Task<byte[]> GridFSBucketDownload(string id);
+ Task<string> GridFSBucketUploadFromBytesAsync(string filename, byte[] source);
+ Task<bool> DatabaseExist(string connectionString);
+ }
+}
diff --git a/src/Core/Grand.Domain/Data/IMongoDBContext.cs b/src/Core/Grand.Domain/Data/IMongoDBContext.cs
deleted file mode 100644
index 06718d515..000000000
--- a/src/Core/Grand.Domain/Data/IMongoDBContext.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using MongoDB.Bson;
-using MongoDB.Driver;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace Grand.Domain.Data
-{
- public interface IMongoDBContext
- {
- IMongoDatabase Database();
- IQueryable<T> Table<T>(string collectionName);
- Task<byte[]> GridFSBucketDownload(string id);
- Task<string> GridFSBucketUploadFromBytesAsync(string filename, byte[] source);
- Task<bool> DatabaseExist(string connectionString);
- TResult RunCommand<TResult>(string command);
- BsonDocument RunCommand(string command);
- TResult RunCommand<TResult>(string command, ReadPreference readpreference);
- BsonValue RunScript(string command, CancellationToken cancellationToken);
- Task<BsonValue> RunScriptAsync(string command, CancellationToken cancellationToken);
- string ExecuteScript(string query);
- IEnumerable<Dictionary<string, object>> Serialize(List<BsonValue> collection);
- }
-}
diff --git a/src/Core/Grand.Domain/Data/IRepository.cs b/src/Core/Grand.Domain/Data/IRepository.cs
index 653f7cd56..cceb27aa8 100644
--- a/src/Core/Grand.Domain/Data/IRepository.cs
+++ b/src/Core/Grand.Domain/Data/IRepository.cs
@@ -1,5 +1,4 @@
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
+using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
@@ -13,20 +12,11 @@ namespace Grand.Domain.Data
public partial interface IRepository<T> where T : BaseEntity
{
- /// <summary>
- /// Gets a collection
- /// </summary>
- IMongoCollection<T> Collection { get; }
-
/// <summary>
/// Sets a collection
/// </summary>
bool SetCollection(string collectionName);
- /// <summary>
- /// Gets a database
- /// </summary>
- IMongoDatabase Database { get; }
/// <summary>
/// Get entity by identifier
@@ -48,13 +38,6 @@ namespace Grand.Domain.Data
/// <returns>collection of entities</returns>
Task<List<T>> GetAllAsync();
- /// <summary>
- /// Get first entity in query as async with filterdefinition
- /// </summary>
- /// <param name="filter">filter definition</param>
- /// <returns>entity of <typeparamref name="T"/></returns>
- Task<T> FirstOrDefaultAsync(FilterDefinition<T> filter = null);
-
/// <summary>
/// get first item in query as async
/// </summary>
diff --git a/src/Core/Grand.Domain/Data/BsonUtcDateTimeSerializer.cs b/src/Core/Grand.Domain/Data/Mongo/BsonUtcDateTimeSerializer.cs
similarity index 95%
rename from src/Core/Grand.Domain/Data/BsonUtcDateTimeSerializer.cs
rename to src/Core/Grand.Domain/Data/Mongo/BsonUtcDateTimeSerializer.cs
index 3d6d2bcac..d4dde2371 100644
--- a/src/Core/Grand.Domain/Data/BsonUtcDateTimeSerializer.cs
+++ b/src/Core/Grand.Domain/Data/Mongo/BsonUtcDateTimeSerializer.cs
@@ -2,7 +2,7 @@
using MongoDB.Bson.Serialization.Serializers;
using System;
-namespace Grand.Domain.Data
+namespace Grand.Domain.Data.Mongo
{
public class BsonUtcDateTimeSerializer : DateTimeSerializer
{
diff --git a/src/Core/Grand.Domain/Data/Mongo/MongoDBContext.cs b/src/Core/Grand.Domain/Data/Mongo/MongoDBContext.cs
new file mode 100644
index 000000000..ac7e9bf91
--- /dev/null
+++ b/src/Core/Grand.Domain/Data/Mongo/MongoDBContext.cs
@@ -0,0 +1,72 @@
+using MongoDB.Bson;
+using MongoDB.Driver;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace Grand.Domain.Data.Mongo
+{
+ public class MongoDBContext : IDatabaseContext
+ {
+ protected IMongoDatabase _database;
+
+ public MongoDBContext()
+ {
+
+ }
+
+ public MongoDBContext(IMongoDatabase mongodatabase)
+ {
+ _database = mongodatabase;
+ }
+
+ public IMongoDatabase Database()
+ {
+ return _database;
+ }
+
+ public IQueryable<T> Table<T>(string collectionName)
+ {
+ return _database.GetCollection<T>(collectionName).AsQueryable();
+ }
+
+ protected IMongoDatabase TryReadMongoDatabase()
+ {
+ var connectionString = DataSettingsManager.LoadSettings().ConnectionString;
+
+ var mongourl = new MongoUrl(connectionString);
+ var databaseName = mongourl.DatabaseName;
+ var mongodb = new MongoClient(connectionString).GetDatabase(databaseName);
+ return mongodb;
+ }
+
+ public async Task<byte[]> GridFSBucketDownload(string id)
+ {
+ var bucket = new MongoDB.Driver.GridFS.GridFSBucket(_database);
+ var binary = await bucket.DownloadAsBytesAsync(new ObjectId(id), new MongoDB.Driver.GridFS.GridFSDownloadOptions() { CheckMD5 = true, Seekable = true });
+ return binary;
+
+ }
+ public async Task<string> GridFSBucketUploadFromBytesAsync(string filename, byte[] source)
+ {
+ var database = _database ?? TryReadMongoDatabase();
+ var bucket = new MongoDB.Driver.GridFS.GridFSBucket(database);
+ var id = await bucket.UploadFromBytesAsync(filename, source);
+ return id.ToString();
+ }
+
+ public async Task<bool> DatabaseExist(string connectionString)
+ {
+ var client = new MongoClient(connectionString);
+ var databaseName = new MongoUrl(connectionString).DatabaseName;
+ var database = client.GetDatabase(databaseName);
+ await database.RunCommandAsync((Command<BsonDocument>)"{ping:1}");
+
+ var filter = new BsonDocument("name", "GrandNodeVersion");
+ var found = database.ListCollectionsAsync(new ListCollectionsOptions { Filter = filter }).Result;
+ if (found.Any())
+ return true;
+ else
+ return false;
+ }
+ }
+}
diff --git a/src/Core/Grand.Domain/Data/MongoDBMapperConfiguration.cs b/src/Core/Grand.Domain/Data/Mongo/MongoDBMapperConfiguration.cs
similarity index 97%
rename from src/Core/Grand.Domain/Data/MongoDBMapperConfiguration.cs
rename to src/Core/Grand.Domain/Data/Mongo/MongoDBMapperConfiguration.cs
index e75d0bfd9..d61eae19b 100644
--- a/src/Core/Grand.Domain/Data/MongoDBMapperConfiguration.cs
+++ b/src/Core/Grand.Domain/Data/Mongo/MongoDBMapperConfiguration.cs
@@ -6,7 +6,7 @@ using MongoDB.Bson.Serialization.Serializers;
using System;
using System.Collections.Generic;
-namespace Grand.Domain.Data
+namespace Grand.Domain.Data.Mongo
{
public static class MongoDBMapperConfiguration
{
diff --git a/src/Core/Grand.Domain/Data/Repository.cs b/src/Core/Grand.Domain/Data/Mongo/MongoRepository.cs
similarity index 91%
rename from src/Core/Grand.Domain/Data/Repository.cs
rename to src/Core/Grand.Domain/Data/Mongo/MongoRepository.cs
index 4ab4e2766..6a3f68a9f 100644
--- a/src/Core/Grand.Domain/Data/Repository.cs
+++ b/src/Core/Grand.Domain/Data/Mongo/MongoRepository.cs
@@ -8,12 +8,12 @@ using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;
-namespace Grand.Domain.Data
+namespace Grand.Domain.Data.Mongo
{
/// <summary>
/// MongoDB repository
/// </summary>
- public partial class Repository<T> : IRepository<T> where T : BaseEntity
+ public partial class MongoRepository<T> : IRepository<T> where T : BaseEntity
{
#region Fields
@@ -54,7 +54,7 @@ namespace Grand.Domain.Data
/// <summary>
/// Ctor
/// </summary>
- public Repository()
+ public MongoRepository()
{
var connection = DataSettingsManager.LoadSettings();
@@ -66,7 +66,7 @@ namespace Grand.Domain.Data
_collection = _database.GetCollection<T>(typeof(T).Name);
}
}
- public Repository(string connectionString)
+ public MongoRepository(string connectionString)
{
var client = new MongoClient(connectionString);
var databaseName = new MongoUrl(connectionString).DatabaseName;
@@ -75,7 +75,7 @@ namespace Grand.Domain.Data
}
- public Repository(IMongoDatabase database)
+ public MongoRepository(IMongoDatabase database)
{
_database = database;
_collection = _database.GetCollection<T>(typeof(T).Name);
@@ -113,19 +113,6 @@ namespace Grand.Domain.Data
return _collection.AsQueryable().ToListAsync();
}
- /// <summary>
- /// get first item in query as async with filterdefinition
- /// </summary>
- /// <param name="filter"></param>
- /// <returns>entity of <typeparamref name="T"/></returns>
- public virtual Task<T> FirstOrDefaultAsync(FilterDefinition<T> filter = null)
- {
- if (filter == null)
- return _collection.AsQueryable().FirstOrDefaultAsync();
-
- return _collection.Find(filter).FirstOrDefaultAsync();
- }
-
/// <summary>
/// get first item in query as async
/// </summary>
@@ -243,9 +230,9 @@ namespace Grand.Domain.Data
/// <param name="updateBuilder"></param>
/// <returns></returns>
public virtual async Task UpdateOneAsync(Expression<Func<T, bool>> filterexpression, UpdateBuilder<T> updateBuilder)
- {
+ {
var update = Builders<T>.Update.Combine(updateBuilder.Fields);
- var result = await _collection.UpdateOneAsync(filterexpression, update);
+ await _collection.UpdateOneAsync(filterexpression, update);
}
/// <summary>
@@ -257,7 +244,7 @@ namespace Grand.Domain.Data
public virtual async Task UpdateManyAsync(Expression<Func<T, bool>> filterexpression, UpdateBuilder<T> updateBuilder)
{
var update = Builders<T>.Update.Combine(updateBuilder.Fields);
- var result = await _collection.UpdateManyAsync(filterexpression, update);
+ await _collection.UpdateManyAsync(filterexpression, update);
}
// <summary>
@@ -297,7 +284,7 @@ namespace Grand.Domain.Data
MemberInfo minfo = me.Member;
var update = Builders<T>.Update.Set($"{minfo.Name}.$", value);
- var result = await _collection.UpdateOneAsync(filter, update);
+ await _collection.UpdateOneAsync(filter, update);
}
/// <summary>
@@ -320,11 +307,11 @@ namespace Grand.Domain.Data
if (updateMany)
{
- var result = await _collection.UpdateManyAsync(filter, update);
+ await _collection.UpdateManyAsync(filter, update);
}
else
{
- var result = await _collection.UpdateOneAsync(filter, update);
+ await _collection.UpdateOneAsync(filter, update);
}
}
@@ -369,11 +356,11 @@ namespace Grand.Domain.Data
var update = Builders<T>.Update.PullFilter(field, Builders<U>.Filter.Eq(elemFieldMatch, elemMatch));
if (updateMany)
{
- var result = await _collection.UpdateManyAsync(filter, update);
+ await _collection.UpdateManyAsync(filter, update);
}
else
{
- var result = await _collection.UpdateOneAsync(filter, update);
+ await _collection.UpdateOneAsync(filter, update);
}
}
@@ -389,7 +376,7 @@ namespace Grand.Domain.Data
{
var filter = Builders<T>.Filter.Eq(x => x.Id, id);
var update = Builders<T>.Update.PullFilter(field, elemFieldMatch);
- var result = await _collection.UpdateOneAsync(filter, update);
+ await _collection.UpdateOneAsync(filter, update);
}
/// <summary>
/// Delete subdocument
@@ -404,11 +391,11 @@ namespace Grand.Domain.Data
var update = Builders<T>.Update.Pull(field, element);
if (updateMany)
{
- var result = await _collection.UpdateManyAsync(filter, update);
+ await _collection.UpdateManyAsync(filter, update);
}
else
{
- var result = await _collection.UpdateOneAsync(filter, update);
+ await _collection.UpdateOneAsync(filter, update);
}
}
/// <summary>
diff --git a/src/Core/Grand.Domain/Data/MongoDBContext.cs b/src/Core/Grand.Domain/Data/MongoDBContext.cs
deleted file mode 100644
index a8a9e8510..000000000
--- a/src/Core/Grand.Domain/Data/MongoDBContext.cs
+++ /dev/null
@@ -1,139 +0,0 @@
-using MongoDB.Bson;
-using MongoDB.Driver;
-using MongoDB.Driver.Core.Bindings;
-using MongoDB.Driver.Core.Operations;
-using MongoDB.Driver.Linq;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace Grand.Domain.Data
-{
- public class MongoDBContext : IMongoDBContext
- {
- protected IMongoDatabase _database;
- public MongoDBContext()
- {
-
- }
-
- public MongoDBContext(IMongoDatabase mongodatabase)
- {
- _database = mongodatabase;
- }
-
- public IMongoDatabase Database()
- {
- return _database;
- }
-
- public IQueryable<T> Table<T>(string collectionName)
- {
- return _database.GetCollection<T>(collectionName).AsQueryable();
- }
-
- protected IMongoDatabase TryReadMongoDatabase()
- {
- var connectionString = DataSettingsManager.LoadSettings().ConnectionString;
-
- var mongourl = new MongoUrl(connectionString);
- var databaseName = mongourl.DatabaseName;
- var mongodb = new MongoClient(connectionString).GetDatabase(databaseName);
- return mongodb;
- }
-
- public async Task<byte[]> GridFSBucketDownload(string id)
- {
- var bucket = new MongoDB.Driver.GridFS.GridFSBucket(_database);
- var binary = await bucket.DownloadAsBytesAsync(new ObjectId(id), new MongoDB.Driver.GridFS.GridFSDownloadOptions() { CheckMD5 = true, Seekable = true });
- return binary;
-
- }
- public async Task<string> GridFSBucketUploadFromBytesAsync(string filename, byte[] source)
- {
- var database = _database ?? TryReadMongoDatabase();
- var bucket = new MongoDB.Driver.GridFS.GridFSBucket(database);
- var id = await bucket.UploadFromBytesAsync(filename, source);
- return id.ToString();
- }
- public async Task<bool> DatabaseExist(string connectionString)
- {
- var client = new MongoClient(connectionString);
- var databaseName = new MongoUrl(connectionString).DatabaseName;
- var database = client.GetDatabase(databaseName);
- await database.RunCommandAsync((Command<BsonDocument>)"{ping:1}");
-
- var filter = new BsonDocument("name", "GrandNodeVersion");
- var found = database.ListCollectionsAsync(new ListCollectionsOptions { Filter = filter }).Result;
- if (found.Any())
- return true;
- else
- return false;
- }
-
- public TResult RunCommand<TResult>(string command)
- {
- return _database.RunCommand<TResult>(command);
- }
-
- public BsonDocument RunCommand(string command)
- {
- return _database.RunCommand<BsonDocument>(command);
- }
-
- public TResult RunCommand<TResult>(string command, ReadPreference readpreference)
- {
- return _database.RunCommand<TResult>(command, readpreference);
- }
-
- public BsonValue RunScript(string command, CancellationToken cancellationToken)
- {
- var script = new BsonJavaScript(command);
- var operation = new EvalOperation(_database.DatabaseNamespace, script, null);
- var writeBinding = new WritableServerBinding(_database.Client.Cluster, NoCoreSession.NewHandle());
- return operation.Execute(writeBinding, CancellationToken.None);
- }
-
- public Task<BsonValue> RunScriptAsync(string command, CancellationToken cancellationToken)
- {
- var script = new BsonJavaScript(command);
- var operation = new EvalOperation(_database.DatabaseNamespace, script, null);
- var writeBinding = new WritableServerBinding(_database.Client.Cluster, NoCoreSession.NewHandle());
- return operation.ExecuteAsync(writeBinding, CancellationToken.None);
- }
-
- public string ExecuteScript(string query)
- {
- var bscript = new BsonJavaScript(query);
- var operation = new EvalOperation(Database().DatabaseNamespace, bscript, null);
- var writeBinding = new WritableServerBinding(Database().Client.Cluster, NoCoreSession.NewHandle());
- var result = operation.Execute(writeBinding, CancellationToken.None);
- return result["_ns"].ToString();
- }
-
- public virtual IEnumerable<Dictionary<string, object>> Serialize(List<BsonValue> collection)
- {
- var results = new List<Dictionary<string, object>>();
- var columns = new List<string>();
- var document = collection.FirstOrDefault()?.AsBsonDocument;
- if (document != null)
- {
- foreach (var item in document.Names)
- {
- columns.Add(item);
- }
- foreach (var row in collection)
- {
- var myObject = new Dictionary<string, object>();
- foreach (var col in columns)
- {
- myObject.Add(col, row[col].ToString());
- }
- results.Add(myObject);
- }
- }
- return results;
- }
- }
-}
diff --git a/src/Core/Grand.Infrastructure/Startup/StartupApplication.cs b/src/Core/Grand.Infrastructure/Startup/StartupApplication.cs
index ad4380091..fc79cf702 100644
--- a/src/Core/Grand.Infrastructure/Startup/StartupApplication.cs
+++ b/src/Core/Grand.Infrastructure/Startup/StartupApplication.cs
@@ -1,4 +1,5 @@
using Grand.Domain.Data;
+using Grand.Domain.Data.Mongo;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
@@ -40,10 +41,10 @@ namespace Grand.Infrastructure.Startup
}
- serviceCollection.AddScoped<IMongoDBContext, MongoDBContext>();
- //MongoDbRepository
+ serviceCollection.AddScoped<IDatabaseContext, MongoDBContext>();
- serviceCollection.AddScoped(typeof(IRepository<>), typeof(Repository<>));
+ //MongoDbRepository
+ serviceCollection.AddScoped(typeof(IRepository<>), typeof(MongoRepository<>));
}
}
diff --git a/src/Core/Grand.Infrastructure/StartupBase.cs b/src/Core/Grand.Infrastructure/StartupBase.cs
index 7c87cbfef..b66c43fa7 100644
--- a/src/Core/Grand.Infrastructure/StartupBase.cs
+++ b/src/Core/Grand.Infrastructure/StartupBase.cs
@@ -1,6 +1,6 @@
using AutoMapper;
using FluentValidation.AspNetCore;
-using Grand.Domain.Data;
+using Grand.Domain.Data.Mongo;
using Grand.Infrastructure.Caching.RabbitMq;
using Grand.Infrastructure.Configuration;
using Grand.Infrastructure.Mapper;
diff --git a/src/Plugins/Authentication.Facebook/Infrastructure/FacebookAuthenticationBuilder.cs b/src/Plugins/Authentication.Facebook/Infrastructure/FacebookAuthenticationBuilder.cs
index 0372578a8..ffa364d3a 100644
--- a/src/Plugins/Authentication.Facebook/Infrastructure/FacebookAuthenticationBuilder.cs
+++ b/src/Plugins/Authentication.Facebook/Infrastructure/FacebookAuthenticationBuilder.cs
@@ -1,6 +1,7 @@
using Grand.Business.Authentication.Interfaces;
using Grand.Domain.Configuration;
using Grand.Domain.Data;
+using Grand.Domain.Data.Mongo;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Facebook;
using Microsoft.AspNetCore.Authentication.OAuth;
@@ -33,7 +34,7 @@ namespace Authentication.Facebook.Infrastructure
var settings = new FacebookExternalAuthSettings();
try
{
- var fbSettings = new Repository<Setting>(connection.ConnectionString).Table.Where(x => x.Name.StartsWith("facebookexternalauthsettings"));
+ var fbSettings = new MongoRepository<Setting>(connection.ConnectionString).Table.Where(x => x.Name.StartsWith("facebookexternalauthsettings"));
if (fbSettings.Any())
{
var metadata = fbSettings.FirstOrDefault().Metadata;
diff --git a/src/Plugins/Authentication.Google/Infrastructure/GoogleAuthenticationBuilder.cs b/src/Plugins/Authentication.Google/Infrastructure/GoogleAuthenticationBuilder.cs
index cc14161f5..7ef598eab 100644
--- a/src/Plugins/Authentication.Google/Infrastructure/GoogleAuthenticationBuilder.cs
+++ b/src/Plugins/Authentication.Google/Infrastructure/GoogleAuthenticationBuilder.cs
@@ -1,6 +1,7 @@
using Grand.Business.Authentication.Interfaces;
using Grand.Domain.Configuration;
using Grand.Domain.Data;
+using Grand.Domain.Data.Mongo;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Google;
using Microsoft.AspNetCore.Authentication.OAuth;
@@ -33,7 +34,7 @@ namespace Authentication.Google.Infrastructure
var settings = new GoogleExternalAuthSettings();
try
{
- var gSettings = new Repository<Setting>(connection.ConnectionString).Table.Where(x => x.Name.StartsWith("googleexternalauthsettings"));
+ var gSettings = new MongoRepository<Setting>(connection.ConnectionString).Table.Where(x => x.Name.StartsWith("googleexternalauthsettings"));
if (gSettings.Any())
{
var metadata = gSettings.FirstOrDefault().Metadata;
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateIntervalPropertiesCommandHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateIntervalPropertiesCommandHandlerTests.cs
index 230b05695..60b03fd6d 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateIntervalPropertiesCommandHandlerTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateIntervalPropertiesCommandHandlerTests.cs
@@ -2,6 +2,7 @@
using Grand.Business.Catalog.Commands.Models;
using Grand.Domain.Catalog;
using Grand.Domain.Data;
+using Grand.Domain.Data.Mongo;
using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Events;
using MediatR;
@@ -20,7 +21,7 @@ namespace Grand.Business.Catalog.Tests.Handlers
[TestClass()]
public class UpdateIntervalPropertiesCommandHandlerTests
{
- private Mock<IRepository<Product>> _repositoryMock;
+ private Mock<MongoRepository<Product>> _repositoryMock;
private Mock<IMediator> _mediatorMock;
private Mock<ICacheBase> _cacheMock;
private UpdateIntervalPropertiesCommandHandler _handler;
@@ -28,7 +29,7 @@ namespace Grand.Business.Catalog.Tests.Handlers
[TestInitialize()]
public void Init()
{
- _repositoryMock = new Mock<IRepository<Product>>();
+ _repositoryMock = new Mock<MongoRepository<Product>>();
_mediatorMock = new Mock<IMediator>();
_cacheMock = new Mock<ICacheBase>();
_handler = new UpdateIntervalPropertiesCommandHandler(_repositoryMock.Object, _mediatorMock.Object, _cacheMock.Object);
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateProductReviewTotalsCommandHandlerTest.cs b/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateProductReviewTotalsCommandHandlerTest.cs
index 40fe376be..16c8adef9 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateProductReviewTotalsCommandHandlerTest.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateProductReviewTotalsCommandHandlerTest.cs
@@ -4,6 +4,7 @@ using Grand.Business.Catalog.Interfaces.Products;
using Grand.Domain;
using Grand.Domain.Catalog;
using Grand.Domain.Data;
+using Grand.Domain.Data.Mongo;
using Grand.Infrastructure.Caching;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MongoDB.Driver;
@@ -19,7 +20,7 @@ namespace Grand.Business.Catalog.Tests.Handlers
[TestClass()]
public class UpdateProductReviewTotalsCommandHandlerTest
{
- private Mock<IRepository<Product>> _productRepositoryMock;
+ private Mock<MongoRepository<Product>> _productRepositoryMock;
private Mock<ICacheBase> _cacheBaseMock;
private UpdateProductReviewTotalsCommandHandler _updateProductReviewTotalsCommandHandler;
private Mock<IMongoCollection<Product>> _mongoCollectionMock;
@@ -40,7 +41,7 @@ namespace Grand.Business.Catalog.Tests.Handlers
It.IsAny<UpdateOptions>(),
default));
- _productRepositoryMock = new Mock<IRepository<Product>>();
+ _productRepositoryMock = new Mock<MongoRepository<Product>>();
_productRepositoryMock.Setup(x => x.Collection).Returns(_mongoCollectionMock.Object);
_cacheBaseMock = new Mock<ICacheBase>();
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryServiceTests.cs
index a26468cc1..f6d9334a4 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryServiceTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryServiceTests.cs
@@ -1,9 +1,9 @@
using Grand.Business.Catalog.Services.Categories;
using Grand.Business.Common.Interfaces.Security;
-using Grand.Business.Common.Interfaces.Stores;
using Grand.Domain.Catalog;
using Grand.Domain.Customers;
using Grand.Domain.Data;
+using Grand.Domain.Data.Mongo;
using Grand.Infrastructure;
using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Events;
@@ -14,7 +14,6 @@ using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -26,7 +25,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
{
private Mock<ICacheBase> _casheManagerMock;
private Mock<IRepository<Grand.Domain.Catalog.Category>> _categoryRepositoryMock;
- private Mock<IRepository<Product>> _productRepositoryMock;
+ private Mock<MongoRepository<Product>> _productRepositoryMock;
private Mock<IWorkContext> _workContextMock;
private Mock<IMediator> _mediatorMock;
private Mock<IAclService> _aclServiceMock;
@@ -39,7 +38,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
{
_casheManagerMock = new Mock<ICacheBase>();
_categoryRepositoryMock = new Mock<IRepository<Grand.Domain.Catalog.Category>>();
- _productRepositoryMock = new Mock<IRepository<Product>>();
+ _productRepositoryMock = new Mock<MongoRepository<Product>>();
_workContextMock = new Mock<IWorkContext>();
_mediatorMock = new Mock<IMediator>();
_aclServiceMock = new Mock<IAclService>();
@@ -111,7 +110,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
var allCategory = GetMockCategoryList();
var category = new Grand.Domain.Catalog.Category() { Id = "6", ParentCategoryId = "1", Published = true };
_workContextMock.Setup(c => c.CurrentStore).Returns(() => new Domain.Stores.Store() { Id = "" });
- _aclServiceMock.Setup(a => a.Authorize<Grand.Domain.Catalog.Category>(It.IsAny<Grand.Domain.Catalog.Category>(),It.IsAny<Customer>())).Returns(() => true);
+ _aclServiceMock.Setup(a => a.Authorize<Grand.Domain.Catalog.Category>(It.IsAny<Grand.Domain.Catalog.Category>(), It.IsAny<Customer>())).Returns(() => true);
_aclServiceMock.Setup(a => a.Authorize<Grand.Domain.Catalog.Category>(It.IsAny<Grand.Domain.Catalog.Category>(), It.IsAny<string>())).Returns(() => true);
var result = _categoryService.GetCategoryBreadCrumb(category, allCategory);
Assert.IsTrue(result.Count == 3);
@@ -141,13 +140,13 @@ namespace Grand.Business.Catalog.Tests.Service.Category
var result = _categoryService.GetFormattedBreadCrumb(null, allCategory);
Assert.IsTrue(string.IsNullOrEmpty(result));
}
-
+
[TestMethod()]
public async Task DeleteProductCategory_InvokreRepositoryAndClearCache()
{
var collectonMock = new Mock<IMongoCollection<Product>>();
_productRepositoryMock.Setup(p => p.Collection).Returns(collectonMock.Object);
- await _productCategoryService.DeleteProductCategory(new ProductCategory(),"1");
+ await _productCategoryService.DeleteProductCategory(new ProductCategory(), "1");
//TODO
//collectonMock.Verify(c => c.UpdateOneAsync(It.IsAny<FilterDefinition<Product>>(), It.IsAny<UpdateDefinition<Product>>(), null, default(CancellationToken)), Times.Once);
_mediatorMock.Verify(c => c.Publish(It.IsAny<EntityDeleted<ProductCategory>>(), default(CancellationToken)), Times.Once);
@@ -158,7 +157,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
[TestMethod()]
public void DeleteProductCategory_NullArgument_ThrowException()
{
- Assert.ThrowsExceptionAsync<ArgumentNullException>(async () => await _productCategoryService.DeleteProductCategory(null,"id"), "productCategory");
+ Assert.ThrowsExceptionAsync<ArgumentNullException>(async () => await _productCategoryService.DeleteProductCategory(null, "id"), "productCategory");
}
[TestMethod()]
@@ -166,7 +165,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
{
var collectonMock = new Mock<IMongoCollection<Product>>();
_productRepositoryMock.Setup(p => p.Collection).Returns(collectonMock.Object);
- await _productCategoryService.InsertProductCategory(new ProductCategory() ,"id");
+ await _productCategoryService.InsertProductCategory(new ProductCategory(), "id");
//TODO
//collectonMock.Verify(c => c.UpdateOneAsync(It.IsAny<FilterDefinition<Product>>(), It.IsAny<UpdateDefinition<Product>>(), null, default(CancellationToken)), Times.Once);
_mediatorMock.Verify(c => c.Publish(It.IsAny<EntityInserted<ProductCategory>>(), default(CancellationToken)), Times.Once);
@@ -176,9 +175,9 @@ namespace Grand.Business.Catalog.Tests.Service.Category
[TestMethod()]
public void InsertProductCategory_NullArgument_ThrowException()
{
- Assert.ThrowsExceptionAsync<ArgumentNullException>(async () => await _productCategoryService.InsertProductCategory(null,"id"), "productCategory");
+ Assert.ThrowsExceptionAsync<ArgumentNullException>(async () => await _productCategoryService.InsertProductCategory(null, "id"), "productCategory");
}
-
+
private IList<Grand.Domain.Catalog.Category> GetMockCategoryList()
{
return new List<Grand.Domain.Catalog.Category>()
@@ -190,6 +189,6 @@ namespace Grand.Business.Catalog.Tests.Service.Category
new Grand.Domain.Catalog.Category(){ Id="5" ,Name="cat5",Published=true},
};
}
-
+
}
}
diff --git a/src/Tests/Grand.Business.Common.Tests/Services/Addresses/AddressAttributeServiceTests.cs b/src/Tests/Grand.Business.Common.Tests/Services/Addresses/AddressAttributeServiceTests.cs
index 0cadb0d78..6142f7412 100644
--- a/src/Tests/Grand.Business.Common.Tests/Services/Addresses/AddressAttributeServiceTests.cs
+++ b/src/Tests/Grand.Business.Common.Tests/Services/Addresses/AddressAttributeServiceTests.cs
@@ -1,6 +1,7 @@
using Grand.Business.Common.Services.Addresses;
using Grand.Domain.Common;
using Grand.Domain.Data;
+using Grand.Domain.Data.Mongo;
using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Events;
using MediatR;
@@ -19,7 +20,7 @@ namespace Grand.Business.Common.Tests.Services.Addresses
public class AddressAttributeServiceTests
{
private Mock<ICacheBase> _cacheMock;
- private Mock<IRepository<AddressAttribute>> _repositoryMock;
+ private Mock<MongoRepository<AddressAttribute>> _repositoryMock;
private Mock<IMediator> _mediatorMock;
private AddressAttributeService _service;
@@ -27,7 +28,7 @@ namespace Grand.Business.Common.Tests.Services.Addresses
public void Init()
{
_cacheMock = new Mock<ICacheBase>();
- _repositoryMock = new Mock<IRepository<AddressAttribute>>();
+ _repositoryMock = new Mock<MongoRepository<AddressAttribute>>();
_mediatorMock = new Mock<IMediator>();
_service = new AddressAttributeService(_cacheMock.Object,_repositoryMock.Object,_mediatorMock.Object);
}
diff --git a/src/Tests/Grand.Business.Storage.Tests/Services/DownloadServiceTests.cs b/src/Tests/Grand.Business.Storage.Tests/Services/DownloadServiceTests.cs
index b6f213385..d9356e429 100644
--- a/src/Tests/Grand.Business.Storage.Tests/Services/DownloadServiceTests.cs
+++ b/src/Tests/Grand.Business.Storage.Tests/Services/DownloadServiceTests.cs
@@ -18,7 +18,7 @@ namespace Grand.Business.Storage.Tests.Services
{
private Mock<IMediator> _mediatorMock;
private Mock<IRepository<Download>> _repositoryMock;
- private Mock<IMongoDBContext> _mongoDBContext;
+ private Mock<IDatabaseContext> _dbContext;
private DownloadService _service;
[TestInitialize]
@@ -26,8 +26,8 @@ namespace Grand.Business.Storage.Tests.Services
{
_mediatorMock = new Mock<IMediator>();
_repositoryMock = new Mock<IRepository<Download>>();
- _mongoDBContext = new Mock<IMongoDBContext>();
- _service = new DownloadService(_repositoryMock.Object, _mongoDBContext.Object, _mediatorMock.Object);
+ _dbContext = new Mock<IDatabaseContext>();
+ _service = new DownloadService(_repositoryMock.Object, _dbContext.Object, _mediatorMock.Object);
}
[TestMethod]
diff --git a/src/Web/Grand.Web.Common/Middleware/DbVersionCheckMiddleware.cs b/src/Web/Grand.Web.Common/Middleware/DbVersionCheckMiddleware.cs
index ea8fe326b..ceb9cdc8e 100644
--- a/src/Web/Grand.Web.Common/Middleware/DbVersionCheckMiddleware.cs
+++ b/src/Web/Grand.Web.Common/Middleware/DbVersionCheckMiddleware.cs
@@ -5,6 +5,7 @@ using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Caching.Constants;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
+using System.Linq;
namespace Grand.Web.Common.Middleware
{
@@ -17,7 +18,11 @@ namespace Grand.Web.Common.Middleware
_next = next;
}
- public async Task Invoke(HttpContext context, ICacheBase cacheBase, IRepository<GrandNodeVersion> repository)
+ public async Task Invoke(
+ HttpContext context,
+ ICacheBase cacheBase,
+
+ IRepository<GrandNodeVersion> repository)
{
if (context == null || context.Request == null)
{
@@ -25,7 +30,7 @@ namespace Grand.Web.Common.Middleware
return;
}
- var version = await cacheBase.GetAsync(CacheKey.GRAND_NODE_VERSION, async () => await repository.FirstOrDefaultAsync());
+ var version = cacheBase.Get(CacheKey.GRAND_NODE_VERSION, () => repository.Table.FirstOrDefault());
if (version == null)
{
await context.Response.WriteAsync($"The database does not exist.");
diff --git a/src/Web/Grand.Web/Controllers/InstallController.cs b/src/Web/Grand.Web/Controllers/InstallController.cs
index 7643e8f9c..fc905cd9f 100644
--- a/src/Web/Grand.Web/Controllers/InstallController.cs
+++ b/src/Web/Grand.Web/Controllers/InstallController.cs
@@ -4,6 +4,7 @@ using Grand.Business.Common.Services.Security;
using Grand.Business.System.Commands.Models.Security;
using Grand.Business.System.Interfaces.Installation;
using Grand.Domain.Data;
+using Grand.Domain.Data.Mongo;
using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Plugins;
using Grand.SharedKernel.Extensions;
@@ -60,8 +61,7 @@ namespace Grand.Web.Controllers
if (installed)
return View(new InstallModel() { Installed = true });
- var model = new InstallModel
- {
+ var model = new InstallModel {
AdminEmail = "[email protected]",
InstallSampleData = false,
DatabaseConnectionString = "",
@@ -69,8 +69,7 @@ namespace Grand.Web.Controllers
};
foreach (var lang in locService.GetAvailableLanguages())
{
- model.AvailableLanguages.Add(new SelectListItem
- {
+ model.AvailableLanguages.Add(new SelectListItem {
Value = Url.RouteUrl("InstallChangeLanguage", new { language = lang.Code }),
Text = lang.Name,
Selected = locService.GetCurrentLanguage().Code == lang.Code,
@@ -79,8 +78,7 @@ namespace Grand.Web.Controllers
//prepare collation list
foreach (var col in locService.GetAvailableCollations())
{
- model.AvailableCollation.Add(new SelectListItem
- {
+ model.AvailableCollation.Add(new SelectListItem {
Value = col.Value,
Text = col.Name,
Selected = locService.GetCurrentLanguage().Code == col.Value,
@@ -137,7 +135,7 @@ namespace Grand.Web.Controllers
try
{
var mdb = new MongoDBContext();
- if(await mdb.DatabaseExist(connectionString))
+ if (await mdb.DatabaseExist(connectionString))
ModelState.AddModelError("", locService.GetResource("AlreadyInstalled"));
}
catch (Exception ex)
@@ -153,8 +151,7 @@ namespace Grand.Web.Controllers
try
{
//save settings
- var settings = new DataSettings
- {
+ var settings = new DataSettings {
ConnectionString = connectionString,
DbProvider = DbProvider.MongoDB
};
@@ -213,8 +210,7 @@ namespace Grand.Web.Controllers
//prepare language list
foreach (var lang in locService.GetAvailableLanguages())
{
- model.AvailableLanguages.Add(new SelectListItem
- {
+ model.AvailableLanguages.Add(new SelectListItem {
Value = Url.RouteUrl("InstallChangeLanguage", new { language = lang.Code }),
Text = lang.Name,
Selected = locService.GetCurrentLanguage().Code == lang.Code,
@@ -224,8 +220,7 @@ namespace Grand.Web.Controllers
//prepare collation list
foreach (var col in locService.GetAvailableCollations())
{
- model.AvailableCollation.Add(new SelectListItem
- {
+ model.AvailableCollation.Add(new SelectListItem {
Value = col.Value,
Text = col.Name,
Selected = locService.GetCurrentLanguage().Code == col.Value,