Beispiel #1
0
        public async static Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var context     = services.GetRequiredService <FagElGamousContext>();
                    var userManager = services.GetRequiredService <UserManager <AppUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    await ContextSeed.SeedRolesAsync(userManager, roleManager);

                    await ContextSeed.SeedAdminAsync(userManager, roleManager);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }
            host.Run();
        }
Beispiel #2
0
        //public static void Main(string[] args)
        //{
        //    CreateHostBuilder(args).Build().Run();
        //}
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var            services      = scope.ServiceProvider;
                var            UserContext   = services.GetRequiredService <ApplicationDbContext>();
                HotelContext   hotelContext  = scope.ServiceProvider.GetService <HotelContext>();
                ISeederService seederService = scope.ServiceProvider.GetService <ISeederService>();
                //If database doesent exist, run the seeder from movieservice
                bool DatabaseDoesNotExist = hotelContext.Database.EnsureCreated();
                if (DatabaseDoesNotExist)
                {
                    seederService.SeedDataBase();
                }
                ;
                if (!UserContext.Database.EnsureCreated())
                {
                    UserContext.Database.Migrate();
                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    await ContextSeed.SeedRolesAsync(userManager, roleManager);

                    await ContextSeed.SeedAdminAsync(userManager, roleManager);
                }
            }
            host.Run();
        }