public static void Main(string[] args) { var deploy = args.Any(x => x == "/deploy"); if (deploy) { args = args.Except(new[] { "/deploy" }).ToArray(); } var host = CreateWebHostBuilder(args).Build(); if (deploy) { long tenatId = 1; var config = host.Services.GetRequiredService <IConfiguration>(); var shardMapManagerConnString = config.GetConnectionString("ShardMapManager"); var shardMapConnString = config.GetConnectionString("ShardMap"); var deployUtil = new DeployUtil(shardMapManagerConnString, shardMapConnString); deployUtil.DeployShardManagerDbIfNotExist(); deployUtil.DeployTenantDbIfNotExist(tenatId); var userSeeder = new UserSeeder(shardMapConnString); userSeeder.SeedDefaultUser(tenatId); var productSeeder = new ProductSeeder(shardMapConnString); productSeeder.SeedProducts(tenatId); return; } host.Run(); }
public async Task <Unit> Handle(ProductSeedCommand request, CancellationToken cancellationToken) { var list = ProductSeeder.GetProducts(); var testName = list.First().Name; if (!(await _dbContext.Products.AnyAsync(x => x.Name == testName))) { _dbContext.Products.AddRange(list); await _dbContext.SaveChangesAsync(cancellationToken); } return(Unit.Value); }
public static void EnsureSeedDataForContext(this EshopDbContext context) { // first, clear the database. This ensures we can always start context.Database.EnsureDeleted(); context.Database.EnsureCreated(); RolesSeeder.Seed(context); UsersSeeder.Seed(context); VendorSeeder.Seed(context); CategorySeeder.Seed(context); ProductStateSeeder.Seed(context); ProductSeeder.Seed(context); OrderStateSeeder.Seed(context); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <ApplicationDbContext>(); AdminSeeder.SeedDatabase(context, services).Wait(); CategorySeeder.SeedDatabase(context).Wait(); ProductSeeder.SeedDatabase(context).Wait(); } Directory.SetCurrentDirectory(AppContext.BaseDirectory); host.Run(); }