Esempio n. 1
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            // Creating new customer.
            Customer newCustomer = new Customer
            {
                FIRST_NAME         = "Iliya",
                LAST_NAME          = "Tsvibel",
                USER_NAME          = "Iliya",
                PASSWORD           = "******",
                ADDRESS            = "Rishon",
                PHONE_NO           = "0546800559",
                CREDIT_CARD_NUMBER = "12345"
            };

            adminFacade.CreateNewCustomer(defaultToken, newCustomer);

            // Creating new country.
            Country country = null;

            country = new Country();
            for (int i = 0; i < ListOfCountries.CountryNames.Length; i++)
            {
                country = countryDAO.GetByName(ListOfCountries.CountryNames[i]);

                if (country == null)
                {
                    Country newCountry = new Country {
                        COUNTRY_NAME = ListOfCountries.CountryNames[i]
                    };
                    adminFacade.CreateNewCountry(defaultToken, newCountry);
                }
            }

            // Creating new administrator.
            Administrator newAdmin = new Administrator {
                FIRST_NAME = "Iliya", LAST_NAME = "Tsvibel", USER_NAME = "Admin", PASSWORD = "******"
            };

            adminFacade.CreateNewAdmin(defaultToken, newAdmin);

            //Creating new airline.
            //AirlineCompany newAirline = new AirlineCompany
            //{
            //    AIRLINE_NAME = "Aeroflot",
            //    USER_NAME = "Vladimir",
            //    COUNTRY_CODE = adminFacade.GetCountryByName("Germany").ID,
            //    PASSWORD = "******"
            //};
            //adminFacade.CreateNewAirline(defaultToken, newAirline);

            AirlineCompany airline = null;

            airline = new AirlineCompany();
            long countryStartID = 0;

            countryStartID = countryDAO.GetByName(ListOfCountries.CountryNames[0]).ID;
            for (int i = 0; i < ListOfAirlinesCompanies.AirlineNames.Length; i++)
            {
                airline = airlineDAO.GetAirlineByName(ListOfAirlinesCompanies.AirlineNames[i]);

                if (airline == null)
                {
                    AirlineCompany newAirline = new AirlineCompany {
                        AIRLINE_NAME = ListOfAirlinesCompanies.AirlineNames[i], USER_NAME = "UserName-" + ListOfAirlinesCompanies.AirlineNames[i], PASSWORD = random.Next(1000, 10000).ToString(), COUNTRY_CODE = random.Next(Convert.ToInt32(countryStartID), (Convert.ToInt32(countryStartID) + ListOfCountries.CountryNames.Length))
                    };
                    adminFacade.CreateNewAirline(defaultToken, newAirline);
                }
            }

            // Creating new flight.
            Flight flight = new Flight {
                AIRLINECOMPANY_ID = adminFacade.GetAirlineByName(adminToken, "SOLAR CARGO, C.A.").ID, DEPARTURE_TIME = DateTime.Now, LANDING_TIME = DateTime.Now + TimeSpan.FromHours(1), ORIGIN_COUNTRY_CODE = adminFacade.GetCountryByName("Germany").ID, DESTINATION_COUNTRY_CODE = adminFacade.GetCountryByName("Germany").ID, REMAINING_TICKETS = 250
            };

            //airlineFacade.CreateFlight(defaultAirlioneToken, flight);
            flightDAO.Add(flight);

            // Creating new ticket.
            Ticket tickets = new Ticket {
                FLIGHT_ID = anonFacade.GetFlightsByDestinationCountryForTest(adminFacade.GetCountryByName("Germany").ID).ID, CUSTOMER_ID = adminFacade.GetCustomerByUserName(adminToken, "Iliya").ID
            };

            //customerFacade.PurchaseTicket(defaultCustomerToken, tickets);
            ticketDAO.Add(tickets);
            MessageBox.Show($"All data successfully added");
        }