예제 #1
0
        private void InitializeDataCount()
        {
            Task.Run(() =>
            {
                TestFacade facade = new TestFacade();

                CustomersField.CurrentItemsNumber = facade.GetAllCustomers().Count;
                AirlinesField.CurrentItemsNumber  = facade.GetAllAirlineCompanies().Count;
                FlightsField.CurrentItemsNumber   = facade.GetAllFlights().Count;
                TicketsField.CurrentItemsNumber   = facade.GetAllTickets().Count;
            });
        }
예제 #2
0
        /// <summary>
        /// Generates random flights for each airline company.
        /// Read the comment in the bottom of the file to understand its logics.
        /// </summary>
        public static IList <Flight> GetRandomFlights(int flightsPerAirline)
        {
            TestFacade facade = new TestFacade();

            // Getting all airline companies.
            IList <AirlineCompany> airlines = facade.GetAllAirlineCompanies();

            IList <Flight> flights = new List <Flight>();

            Random rnd = new Random();

            DateTime startDate;

            // Defining the initial time of the flights generation.
            DateTime sDate = DateTime.Now.AddDays(-1);

            startDate = new DateTime(sDate.Year, sDate.Month, sDate.Day, sDate.Hour, 0, 0);

            foreach (AirlineCompany airline in airlines)
            {
                for (int i = 0; i < flightsPerAirline; i++)
                {
                    Flight flight = new Flight();
                    flight.AirlineCompanyId = airline.Id;

                    // Choosing random countries
                    if (i % 2 == 0)
                    {
                        flight.OriginCountryCode = airline.CountryCode;
                        do
                        {
                            flight.DestinationCountryCode = rnd.Next(1, 15);
                        }while (flight.DestinationCountryCode == flight.OriginCountryCode);
                    }
                    else
                    {
                        flight.DestinationCountryCode = airline.CountryCode;
                        do
                        {
                            flight.OriginCountryCode = rnd.Next(1, 15);
                        }while (flight.DestinationCountryCode == flight.OriginCountryCode);
                    }

                    // Generating flight schedule:

                    flight.DepartureTime = startDate.AddMinutes(i * 60);

                    int flightTime = GetFlightDuration(flight.OriginCountryCode, flight.DestinationCountryCode);

                    flight.LandingTime = flight.DepartureTime.AddHours(flightTime);

                    if (rnd.Next(1, 3) == 1)
                    {
                        if (rnd.Next(1, 3) == 1)
                        {
                            flight.LandingTime = flight.LandingTime.AddMinutes(30);
                        }
                        else
                        {
                            flight.LandingTime = flight.LandingTime.AddMinutes(-30);
                        }
                    }

                    // Generating tickets number and ticket price:

                    flight.RemainingTickets = rnd.Next(10, 150);

                    flight.TicketPrice = flightTime * 50 - 1;

                    flights.Add(flight);
                }
            }

            return(flights);
        }