Exemple #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);
                }
            }
        }
Exemple #2
0
        private static void CreateDefaultFlights(IServiceProvider serviceProvider)
        {
            IFlightsRepository flightsRepository = serviceProvider.GetService <IFlightsRepository>();

            if (flightsRepository.GetAll().Count == 0)
            {
                Random         random            = new Random();
                FlightStatus[] incomingStatuses  = new[] { FlightStatus.Expected, FlightStatus.Delayed, FlightStatus.Landed };
                FlightStatus[] departingStatuses = new[] { FlightStatus.Canceled, FlightStatus.OnTime, FlightStatus.Departed, FlightStatus.Canceled };
                string[]       places            = new[] { "Moscow", "New York", "Sydney", "Los Angeles", "Berlin", "Tokyo", "Paris", "Istanbul", "Rome", "Krakow", "Singapore" };
                for (int i = 0; i < random.Next(5, 10); i++)
                {
                    Flight incomingFlight = new Flight()
                    {
                        TailNumber   = $"{(char)('A' + random.Next(26))}{(char)('A' + random.Next(26))} {(char)('0' + random.Next(9))}{(char)('0' + random.Next(9))}",
                        FlightType   = FlightType.IncomingFlight,
                        Airline      = "International Airline",
                        FlightStatus = incomingStatuses[random.Next(incomingStatuses.Length)],
                        Place        = places[random.Next(places.Length)],
                        Date         = DateTime.Now.AddHours(random.Next(1, 10))
                    };
                    flightsRepository.Save(incomingFlight);
                }
                for (int i = 0; i < random.Next(5, 10); i++)
                {
                    Flight departingFlight = new Flight()
                    {
                        TailNumber   = $"{(char)('A' + random.Next(26))}{(char)('A' + random.Next(26))} {(char)('0' + random.Next(9))}{(char)('0' + random.Next(9))}",
                        FlightType   = FlightType.DepartingFlight,
                        Airline      = "International Airline",
                        FlightStatus = departingStatuses[random.Next(departingStatuses.Length)],
                        Place        = places[random.Next(places.Length)],
                        Date         = DateTime.Now.AddHours(random.Next(1, 10))
                    };
                    flightsRepository.Save(departingFlight);
                }
            }
        }
Exemple #3
0
        private void ConvertFlights(List <Flight> flights, IFlightsRepository _flightsRepository)
        {
            Random random = new Random();

            string[] places = new string[] { "Moscow", "New York", "Sydney", "Los Angeles", "Berlin", "Tokyo", "Paris", "Istanbul", "Rome", "Krakow", "Singapore" };
            foreach (var flight in flights)
            {
                if (flight.FlightStatus == FlightStatus.Landed)
                {
                    flight.Place        = places[random.Next(places.Length)];
                    flight.FlightType   = FlightType.DepartingFlight;
                    flight.FlightStatus = FlightStatus.OnTime;
                }
                else if (flight.FlightStatus == FlightStatus.Departed)
                {
                    flight.FlightType   = FlightType.IncomingFlight;
                    flight.FlightStatus = FlightStatus.Expected;
                }
                flight.Date = DateTime.Now.AddDays(random.Next(5)).AddHours(random.Next(12)).AddMinutes(random.Next(30));
                _flightsRepository.Save(flight);
            }
        }
Exemple #4
0
        public IFlight Save(IFlight entity)
        {
            m_Repository.Save(entity);

            return(entity);
        }