Ejemplo n.º 1
0
        public static async Task Main(string[] args)
        {
            var host  = CreateHostBuilder(args).Build();
            var scope = host.Services.CreateScope();

            using (scope)
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var context     = services.GetRequiredService <StoreContext>();
                    var userManager = services.GetRequiredService <UserManager <User> >();
                    await context.Database.MigrateAsync();

                    await UserSeed.SeedUserAsync(userManager, context);

                    await CategorySeed.SeedCategoryAsync(context);

                    await SubCategorySeed.SeedSubCategory(context);

                    await ProductSeed.SeedProductAsync(context, userManager);

                    await ProductImagesSeed.SeedProductImages(context);

                    await ProductLinkSubCategory.SeedProductLinkSubCategoriesAsync(context);

                    await VIPAdsSeed.SeedVIPAds(context);
                }
                catch (Exception e)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(e, "error happen in migration");
                }
            }
            host.Run();
        }