Beispiel #1
0
 private static async Task <IEnumerable <Ticket> > GetPreconfiguredTickets(ScannerContext scannerContext)
 {
     return(new List <Ticket>()
     {
         new Ticket()
         {
             FlightId = scannerContext.Flights.Include(f => f.StartLocation).Where(f => f.StartLocation.Country == "Ukraine").FirstOrDefault().Id,
             CabinClassId = 1,
             PassengerFirstName = "Valerii",
             PassengerLastName = "Zhmyshenko",
             PassengerBirthdate = DateTime.Now.AddYears(-54),
             PassengerPassport = "000123456"
         }
     });
 }
Beispiel #2
0
        private static async Task <IEnumerable <Flight> > GetPreconfiguredFlights(ScannerContext scannerContext)
        {
            IList <Location> locations = await scannerContext.Locations.ToListAsync();

            return(new List <Flight>()
            {
                new Flight()
                {
                    Name = "TestFlight#1337",
                    StartDateTime = DateTime.Now,
                    EndDateTime = DateTime.Now.AddHours(3),
                    StartLocationId = locations.Where(l => l.IATA == "KBP").FirstOrDefault().Id,
                    EndLocationId = locations.Where(l => l.IATA == "WAW").FirstOrDefault().Id
                }
            });
        }
Beispiel #3
0
        public static async Task SeedAsync(ScannerContext scannerContext, ILoggerFactory loggerFactory, IEntityGenerator <Flight, Location> entityGenerator, int?retry = 0)
        {
            int retryForAvailability = retry.Value;

            try
            {
                if (!scannerContext.CabinClasses.Any())
                {
                    scannerContext.CabinClasses.AddRange(GetPreconfiguredCabinClasses());
                    await scannerContext.SaveChangesAsync();
                }

                if (!scannerContext.Locations.Any())
                {
                    scannerContext.Locations.AddRange(await GetLocationsFromApi());
                    await scannerContext.SaveChangesAsync();
                }

                if (!scannerContext.Flights.Any())
                {
                    scannerContext.Flights.AddRange(await entityGenerator.GenerateRandomEntities(await scannerContext.Locations.ToListAsync(), 500000));
                    await scannerContext.SaveChangesAsync();
                }

                if (!scannerContext.Tickets.Any())
                {
                    scannerContext.Tickets.AddRange(await GetPreconfiguredTickets(scannerContext));
                    await scannerContext.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                if (retryForAvailability < 3)
                {
                    retryForAvailability++;
                    var log = loggerFactory.CreateLogger <ScannerContextSeed>();
                    log.LogError(ex.Message);
                    await SeedAsync(scannerContext, loggerFactory, entityGenerator, retryForAvailability);
                }
            }
        }