public AlertsController(AwardData.AwardContext context, Microsoft.Extensions.Options.IOptionsMonitor <AppSettings> settingsAccessor) { ctx = context; appSettings = settingsAccessor.CurrentValue; }
public static void Seed(AwardData.AwardContext ctx, Microsoft.AspNetCore.Identity.UserManager <ApplicationUser> userManager) { var routes = getRoutes(); ctx.Routes.AddRange(routes); ctx.SaveChanges(); var client = new HttpClient(); using (HttpResponseMessage response = client.GetAsync("https://awardhacks.se/export/flights").Result) { using (HttpContent content = response.Content) { var json = content.ReadAsStringAsync().Result; var export = Newtonsoft.Json.JsonConvert.DeserializeObject <List <AwardExport> >(json); foreach (var e in export) { var tmp = new Crawl { Id = e.Id, Departure = e.Departure, Arrival = e.Arrival, Business = e.Business, Plus = e.Plus, Go = e.Go, Flight = e.Flight, TravelDate = e.Departure.Date, CrawlDate = DateTime.Now, Equipment = e.Equipment, Success = true }; tmp.RouteId = routes.Where(r => r.To == e.Destination && r.From == e.Origin).Select(r => r.Id).FirstOrDefault(); if (tmp.RouteId == 0) { tmp.RouteId = routes.Where(r => r.To == e.Origin && r.From == e.Destination).Select(r => r.Id).FirstOrDefault(); tmp.Return = true; } ctx.Crawls.Add(tmp); } } } ctx.SaveChanges(); var ofData = new OpenFlightsData.OFData(); ofData.LoadData(); int id = 0; foreach (var iata in ctx.Routes.Select(r => r.To).Union(ctx.Routes.Select(r => r.From)).Distinct()) { var ap = ofData.Airports.FirstOrDefault(ap => iata.Equals(ap.IATA, StringComparison.OrdinalIgnoreCase)); if (ap != null) { ctx.Airports.Add(new Airport { Id = ++id, City = ap.City, IATA = ap.IATA, Country = ap.Country, //This is not correct for Africa etc but will do for the current routes. Zone = ap.Country == "United States" ? "North & Central America" : ap.Timezone > -4 && ap.Timezone < 5 ? "Europe" : "Central Asia & Far East Asia" } ); } ; } ctx.SaveChanges(); userManager.CreateAsync(new ApplicationUser { Email = "*****@*****.**", EmailConfirmed = true, UserName = "******" }, "someweaktestpwd"); ctx.SaveChanges(); }
public HomeController(AwardData.AwardContext context) { ctx = context; }