diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductTypes/IProductTypeDataSeeder.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductTypes/IProductTypeDataSeeder.cs new file mode 100644 index 00000000..9f8e9c77 --- /dev/null +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductTypes/IProductTypeDataSeeder.cs @@ -0,0 +1,10 @@ +using System.Threading.Tasks; +using Volo.Abp.Data; + +namespace EasyAbp.EShop.Products.ProductTypes +{ + public interface IProductTypeDataSeeder + { + Task SeedAsync(DataSeedContext context); + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductTypes/ProductTypeDataSeeder.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductTypes/ProductTypeDataSeeder.cs new file mode 100644 index 00000000..4eb86e5e --- /dev/null +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductTypes/ProductTypeDataSeeder.cs @@ -0,0 +1,31 @@ +using System.Threading.Tasks; +using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Guids; +using Volo.Abp.MultiTenancy; + +namespace EasyAbp.EShop.Products.ProductTypes +{ + public class ProductTypeDataSeeder : IProductTypeDataSeeder, ITransientDependency + { + private readonly IGuidGenerator _guidGenerator; + private readonly IProductTypeRepository _productTypeRepository; + + public ProductTypeDataSeeder( + IGuidGenerator guidGenerator, + IProductTypeRepository productTypeRepository) + { + _guidGenerator = guidGenerator; + _productTypeRepository = productTypeRepository; + } + + public async Task SeedAsync(DataSeedContext context) + { + if (await _productTypeRepository.GetCountAsync() == 0) + { + await _productTypeRepository.InsertAsync(new ProductType(_guidGenerator.Create(), "Default", "Default", + null, MultiTenancySides.Both), true); + } + } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductsDataSeedContributor.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductsDataSeedContributor.cs new file mode 100644 index 00000000..82c00acc --- /dev/null +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductsDataSeedContributor.cs @@ -0,0 +1,24 @@ +using System.Threading.Tasks; +using EasyAbp.EShop.Products.ProductTypes; +using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Uow; + +namespace EasyAbp.EShop.Products +{ + public class ProductsDataSeedContributor : IDataSeedContributor, ITransientDependency + { + private readonly IProductTypeDataSeeder _productTypeDataSeeder; + + public ProductsDataSeedContributor(IProductTypeDataSeeder productTypeDataSeeder) + { + _productTypeDataSeeder = productTypeDataSeeder; + } + + [UnitOfWork(true)] + public async Task SeedAsync(DataSeedContext context) + { + await _productTypeDataSeeder.SeedAsync(context); + } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Settings/StoresSettingDefinitionProvider.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Settings/StoresSettingDefinitionProvider.cs index ece3d4e4..3e31781d 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Settings/StoresSettingDefinitionProvider.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Settings/StoresSettingDefinitionProvider.cs @@ -9,6 +9,8 @@ namespace EasyAbp.EShop.Stores.Settings /* Define module settings here. * Use names from StoresSettings class. */ + + context.Add(new SettingDefinition(StoresSettings.DefaultProductTypeDisplayName, "My store")); } } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Settings/StoresSettings.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Settings/StoresSettings.cs index e929f429..3d04ed54 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Settings/StoresSettings.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Settings/StoresSettings.cs @@ -7,5 +7,7 @@ /* Add constants for setting names. Example: * public const string MySettingName = GroupName + ".MySettingName"; */ + + public const string DefaultProductTypeDisplayName = GroupName + ".DefaultProductTypeDisplayName"; } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/IStoreDataSeeder.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/IStoreDataSeeder.cs new file mode 100644 index 00000000..16757ade --- /dev/null +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/IStoreDataSeeder.cs @@ -0,0 +1,10 @@ +using System.Threading.Tasks; +using Volo.Abp.Data; + +namespace EasyAbp.EShop.Stores.Stores +{ + public interface IStoreDataSeeder + { + Task SeedAsync(DataSeedContext context); + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/Store.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/Store.cs index a68f1777..ce7c9f7b 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/Store.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/Store.cs @@ -18,8 +18,10 @@ namespace EasyAbp.EShop.Stores.Stores public Store( Guid id, + Guid? tenantId, [NotNull] string name) : base(id) { + TenantId = tenantId; Name = name; } } diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/StoreDataSeeder.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/StoreDataSeeder.cs new file mode 100644 index 00000000..038dc865 --- /dev/null +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/StoreDataSeeder.cs @@ -0,0 +1,43 @@ +using System.Threading.Tasks; +using EasyAbp.EShop.Stores.Settings; +using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Guids; +using Volo.Abp.MultiTenancy; +using Volo.Abp.Settings; + +namespace EasyAbp.EShop.Stores.Stores +{ + public class StoreDataSeeder : IStoreDataSeeder, ITransientDependency + { + private readonly IGuidGenerator _guidGenerator; + private readonly ICurrentTenant _currentTenant; + private readonly ISettingProvider _settingProvider; + private readonly IStoreRepository _storeRepository; + + public StoreDataSeeder( + IGuidGenerator guidGenerator, + ICurrentTenant currentTenant, + ISettingProvider settingProvider, + IStoreRepository storeRepository) + { + _guidGenerator = guidGenerator; + _currentTenant = currentTenant; + _settingProvider = settingProvider; + _storeRepository = storeRepository; + } + + public async Task SeedAsync(DataSeedContext context) + { + using (_currentTenant.Change(context.TenantId)) + { + if (await _storeRepository.GetCountAsync() == 0) + { + await _storeRepository.InsertAsync( + new Store(_guidGenerator.Create(), _currentTenant.Id, + await _settingProvider.GetOrNullAsync(StoresSettings.DefaultProductTypeDisplayName)), true); + } + } + } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoresDataSeedContributor.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoresDataSeedContributor.cs new file mode 100644 index 00000000..0f02cfc7 --- /dev/null +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoresDataSeedContributor.cs @@ -0,0 +1,24 @@ +using System.Threading.Tasks; +using EasyAbp.EShop.Stores.Stores; +using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Uow; + +namespace EasyAbp.EShop.Stores +{ + public class StoresDataSeedContributor : IDataSeedContributor, ITransientDependency + { + private readonly IStoreDataSeeder _storeDataSeeder; + + public StoresDataSeedContributor(IStoreDataSeeder storeDataSeeder) + { + _storeDataSeeder = storeDataSeeder; + } + + [UnitOfWork(true)] + public async Task SeedAsync(DataSeedContext context) + { + await _storeDataSeeder.SeedAsync(context); + } + } +} \ No newline at end of file