public EFTempleTourRepo(TempleTourDbContext context) { _context = context; }
public static void EnsurePopulated(IApplicationBuilder application) { Console.WriteLine("Start EnsurePopulated."); TempleTourDbContext context = application.ApplicationServices. CreateScope().ServiceProvider.GetRequiredService <TempleTourDbContext>(); if (context.Database.GetPendingMigrations().Any()) { context.Database.Migrate(); } if (!context.Tours.Any()) { List <Tour> toursToAdd = new List <Tour>(); for (int iOuter = 30; iOuter < 32; iOuter++) { for (int iInner = 8; iInner < 21; iInner++) { toursToAdd.Add( new Tour { TourTime = new DateTime( year: 2021, month: 3, day: iOuter, hour: iInner, minute: 00, second: 00 ), Parties = new List <Party>() } ); } } for (int iOuter = 1; iOuter < 30; iOuter++) { for (int iInner = 8; iInner < 21; iInner++) { toursToAdd.Add( new Tour { TourTime = new DateTime( year: 2021, month: 4, day: iOuter, hour: iInner, minute: 00, second: 00 ), Parties = new List <Party>() } ); } } Console.WriteLine("Finished creating the tours."); context.Tours.AddRange(toursToAdd); Console.WriteLine("Finished adding the tour times to the DB."); context.SaveChanges(); Console.WriteLine("Finished saving changes to the DB."); } }