public static void RunSetup(Configuration configuration) { var dbContext = DbContextFactory.CreateApplicationDbContext(configuration.ConnectionString); Log.Information("Updating database..."); try { dbContext.Database.Migrate(); } catch (Exception e) { Log.Error(e, "Error encountered during update!"); return; }; if (!dbContext.Maps.Any()) { Log.Information("Creating initial map."); var map = Map.Create(); dbContext.Maps.Add(map); } if (!dbContext.GlobalTimeEvents.Any()) { Log.Information("Creating global events"); var events = GlobalTimeEvents.Create(); dbContext.GlobalTimeEvents.Add(events); } if (!dbContext.GlobalConstellation.Any()) { Log.Information("Creating sun and moons"); var constellations = GlobalConstellation.Create(); foreach (var constellation in constellations) { dbContext.GlobalConstellation.Add(constellation); } } if (!dbContext.GlobalData.Any()) { Log.Information("Creating global data"); var database = GlobalData.Create(); foreach (var data in database) { dbContext.GlobalData.Add(data); } } if (!dbContext.Clock.Any()) { Log.Information("Creating clock"); var clock = Clock.Create(); dbContext.Clock.Add(clock); } dbContext.SaveChanges(); }
static Document( ) { Global = new GlobalData( ); Global.Create( ); }