Пример #1
0
        public void GenerateData()
        {
            log.Info("Creating admin user");
            MainWindowViewModel.ListForLog.Add("Creating admin user");
            //Creating admin user:
            IloginAdministrator     = FlyingCenterSystem.GetFlyingCenterSystemInstance().Login("admin", "9999");
            loginTokenAdministrator = IloginAdministrator as LoginToken <Administrator>;
            administratorFacade     = (LoggedInAdministratorFacade)FlyingCenterSystem.GetFlyingCenterSystemInstance().GetFacade(IloginAdministrator);

            //Adds the countries first (foreign key constrain considaration):
            log.Info("Adds the countries first");
            MainWindowViewModel.ListForLog.Add("Adds the countries first");
            for (int i = 0; i < _CountriesNoToAdd; i++)
            {
                administratorFacade.CreateNewCountry(loginTokenAdministrator,
                                                     new Country()
                {
                    CountryName = listOfThings.CountriesArray[rnd.Next(listOfThings.CountriesArray.Length)]
                });
                if (i >= listOfThings.CountriesArray.Length)
                {
                    administratorFacade.CreateNewCountry(loginTokenAdministrator,
                                                         new Country()
                    {
                        CountryName = RandomString(5)
                    });
                }
            }

            //Get All Countries and add country codes for filling the airline companies:
            log.Info("Adds the Airline Companies");
            MainWindowViewModel.ListForLog.Add("Adds the Airline Companies");
            IList <Country> countries = new List <Country>();

            countries = administratorFacade.GetAllCountries(loginTokenAdministrator);

            //Adds the Airline Companies:
            for (int i = 0; i < _AirlineCompaniesNo; i++)
            {
                administratorFacade.CreateNewAirline(loginTokenAdministrator, new AirlineCompany()
                {
                    AirLineName = RandomString(5),
                    CountryCode = countries[rnd.Next(0, countries.Count)].CountyID,
                    Password    = RandomString(6),
                    UserName    = RandomString(4)
                });
            }

            //Adds the Customers:
            log.Info("Adds the Customers");
            MainWindowViewModel.ListForLog.Add("Adds the Customers");
            //FillCustomerTableFromUserApi(CustomersNo); - will not use, site is down (although it's working)
            FillCustomerTableRandomly(rnd, _CustomersNo);

            //Get All AirlineCompanies for the id:
            IList <AirlineCompany> airlineCompanies = administratorFacade.GetAllAirLineCompanies();

            //Adds the Flights Per Company:
            log.Info("Adds the Flights Per Company");
            MainWindowViewModel.ListForLog.Add("Adds the Flights Per Company");
            for (int i = 0; i < _FlightsPerCompany; i++)
            {
                administratorFacade.CreateFlight(loginTokenAdministrator, new Flight()
                {
                    AirLineCompany_ID        = airlineCompanies[rnd.Next(0, airlineCompanies.Count)].Airline_ID,
                    Origin_Country_Code      = countries[rnd.Next(0, countries.Count)].CountyID,
                    Destination_Country_Code = countries[rnd.Next(0, countries.Count)].CountyID,
                    DepartureTime            = createRandomDate(),
                    LandingTime       = createRandomDate(),
                    Remaining_Tickets = rnd.Next(5, 51)
                });
            }

            log.Info("Adds the Tickets per Customer");
            MainWindowViewModel.ListForLog.Add("Adds the Tickets per Customer");
            //Get All customers:
            IList <Customer> customers = new List <Customer>();

            customers = administratorFacade.GetAllCustomers(loginTokenAdministrator);

            //Get All flights :
            IList <Flight> flights = new List <Flight>();

            flights = administratorFacade.GetAllFlights();

            //Adds the Tickets per Customer:
            for (int i = 0; i < _TicketsPerCustomer; i++)
            {
                administratorFacade.AddTicketsToCustomer(loginTokenAdministrator,
                                                         customers[rnd.Next(0, customers.Count)].Customer_ID,
                                                         flights[rnd.Next(0, flights.Count)].FlightID);
            }

            log.Info("Finished puting data in DB!");
            MainWindowViewModel.ListForLog.Add("Finished puting data in DB!");
        }