mirror of https://github.com/EasyAbp/EShop.git
9 changed files with 148 additions and 0 deletions
@ -0,0 +1,10 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Data; |
|||
|
|||
namespace EasyAbp.EShop.Products.ProductTypes |
|||
{ |
|||
public interface IProductTypeDataSeeder |
|||
{ |
|||
Task SeedAsync(DataSeedContext context); |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Data; |
|||
|
|||
namespace EasyAbp.EShop.Stores.Stores |
|||
{ |
|||
public interface IStoreDataSeeder |
|||
{ |
|||
Task SeedAsync(DataSeedContext context); |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue