Esempio n. 1
0
        private static void CreateDefaultFlights(IServiceProvider serviceProvider)
        {
            IFlightsRepository flightsRepository = serviceProvider.GetService <IFlightsRepository>();

            if (!flightsRepository.HasAnyFlights())
            {
                Random         random            = new Random();
                FlightStatus[] incomingStatuses  = new FlightStatus[] { FlightStatus.Expected, FlightStatus.Delayed, FlightStatus.Landed };
                FlightStatus[] departingStatuses = new FlightStatus[] { FlightStatus.Canceled, FlightStatus.OnTime, FlightStatus.Departed, FlightStatus.Canceled };
                string[]       places            = new string[] { "Moscow", "New York", "Sydney", "Los Angeles", "Berlin", "Tokyo", "Paris", "Istanbul", "Rome", "Krakow", "Singapore" };
                string[]       airlines          = new string[] { "International Airline", "Southwest Airline", "Delta Airline", "United Airline", "UC Airline", "Rex Airline" };
                for (int i = 0; i < random.Next(10, 50); i++)
                {
                    Flight departingFlight = new Flight()
                    {
                        TailNumber   = GenerateTailNumber(random),
                        FlightType   = FlightType.DepartingFlight,
                        Airline      = airlines[random.Next(airlines.Length)],
                        FlightStatus = departingStatuses[random.Next(departingStatuses.Length)],
                        Place        = places[random.Next(places.Length)],
                        Date         = DateTime.Now.AddHours(random.Next(12)).AddMinutes(random.Next(30))
                    };
                    flightsRepository.Save(departingFlight);
                }
                for (int i = 0; i < random.Next(10, 50); i++)
                {
                    Flight incomingFlight = new Flight()
                    {
                        TailNumber   = GenerateTailNumber(random),
                        FlightType   = FlightType.IncomingFlight,
                        Airline      = airlines[random.Next(airlines.Length)],
                        FlightStatus = incomingStatuses[random.Next(incomingStatuses.Length)],
                        Place        = places[random.Next(places.Length)],
                        Date         = DateTime.Now.AddHours(random.Next(12)).AddMinutes(random.Next(30))
                    };
                    flightsRepository.Save(incomingFlight);
                }
            }
        }