Пример #1
0
        public static async Task <IWebHost> SeedingData(this IWebHost webHost)
        {
            using (var serviceScope = webHost.Services.CreateScope())
            {
                var userManager        = serviceScope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >();
                var rolesManager       = serviceScope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >();
                var context            = serviceScope.ServiceProvider.GetService <DataContext>();
                var hostingEnvironment = serviceScope.ServiceProvider.GetService <IHostingEnvironment>();

                if (!context.Newss.Any())
                {
                    await DataSeeder.InitData(context);
                }

                await DataSeeder.InitializeAsync(userManager, rolesManager);

                if (!context.Comments.Any())
                {
                    await DataSeeder.InitComment(context);
                }
            }
            return(webHost);
        }
Пример #2
0
        public async Task <IActionResult> Seed()
        {
            await _dataSeeder.InitializeAsync();

            return(Ok("done"));
        }