public async Task InsertingDataBase(string AirlineNo, string CustomerNo, string FlightsPerCmpnyNo, string TicketsPerCustNo, string CountriesNo) { _bgWorker.DoWork += (s, e) => { for (int i = 0; i < 101; i++) { Thread.Sleep(100); ProgressStatus = i; } }; _bgWorker.RunWorkerAsync(); int numberOfAirLines = Int32.Parse(AirlineNo); int numberOfCustomers = Int32.Parse(CustomerNo); int numberOfFlightsPerCmp = Int32.Parse(FlightsPerCmpnyNo); int numberOfTicketsPerCust = Int32.Parse(TicketsPerCustNo); int numberOfCountries = Int32.Parse(CountriesNo); try { await Task.Run(() => { restWorking = new WorkWithAPI(); List <Country> countriesFromRest = restWorking.CountriesApiWebWork(); int countryNoParsed = Convert.ToInt32(CountriesNo); int customerNoParsed = Convert.ToInt32(CustomerNo); int flightNoParsed = Convert.ToInt32(FlightsPerCmpnyNo); int airlineNoParsed = Convert.ToInt32(AirlineNo); int ticketNoParsed = Convert.ToInt32(TicketsPerCustNo); ProggressBarMaxVal = countryNoParsed + customerNoParsed + flightNoParsed + airlineNoParsed + ticketNoParsed; for (int i = 0; i < countryNoParsed; i++) { afc.CreateNewCountry(new LoginToken <Administrator>(), countriesFromRest[i]); ProggressBarVal += i; } List <AirlineCompany> airlines = restWorking.AirlineCompnyApiWork(); for (int i = 0; i < airlineNoParsed; i++) { afc.CreateNewAirline(new LoginToken <Administrator>(), airlines[i]); ProggressBarVal += i; } List <Customer> customersREST = restWorking.CustomerApiWork(); for (int i = 0; i < customerNoParsed; i++) { afc.CreateNewCustomer(new LoginToken <Administrator>(), customersREST[i]); ProggressBarVal += i; } flightsPerCompany = new List <Flight>(); long airlineId = 0; long countryCode = 0; string airlineName = null; long secondCountryCode = 0; DateTime firstDate = new DateTime(); DateTime secondDate = new DateTime(); numberOfFlightsToCreate = RandomFlightToBeCreated(); for (int j = 0; j < airlineNoParsed; j++) { for (int i = 0; i < flightNoParsed; i++) { airlineId = alf.GetRandomAirlineId(); airlineName = alf.GetAirlineNameByID((int)airlineId); countryCode = alf.GetRandomCountryId(); secondCountryCode = alf.GetRandomCountryId(); firstDate = RandomDate(); Thread.Sleep(10); secondDate = RandomDate2(firstDate); flightsPerCompany.Add(new Flight(airlineId, countryCode, secondCountryCode, firstDate, secondDate, RandomTickets(), airlineName, RandomString())); ProggressBarVal += i; } } foreach (var flight in flightsPerCompany) { alf.CreateFlight(airlineToken, flight); } Random rnd = new Random(); int numberOfIds = 0, flightID = 0; List <long> customerIds = cfc.GetAllCustomerID(); LoginService customerLogin = new LoginService(); for (int i = 0; i < customerNoParsed; i++) { for (int j = 0; j < ticketNoParsed; j++) { numberOfIds = rnd.Next(flightNoParsed); Tickets ticket = new Tickets(); customerLogin.TryCustomerLogin(restWorking.CustomerApiWork()[i].USER_NAME, restWorking.CustomerApiWork()[i].PASSWORD, out customerToken); flightID = (int)alf.GetRandomFlightID(); ticket = cfc.PurchaseTicket(customerToken, afc.GetFlightById(flightID)); ticket.CUSTOMER_ID = customerIds[i]; ticket.FLIGHT_ID = flightID; afc.AddTicket(ticket); ProggressBarVal += j; } } }); } catch (Exception) { throw new Exception("Something went wrong while trying to insert data..."); } }
public List <AirlineCompany> CreateCompanies() { companies = new List <AirlineCompany>(); companies.Add(new AirlineCompany { AIRLINE_NAME = "El Al", USER_NAME = "ElAl789", PASSWORD = "******", COUNTRY_CODE = alf.GetRandomCountryId() }); companies.Add(new AirlineCompany { AIRLINE_NAME = "MaroccoAir", USER_NAME = "M78", PASSWORD = "******", COUNTRY_CODE = alf.GetRandomCountryId() }); companies.Add(new AirlineCompany { AIRLINE_NAME = "Four4real", USER_NAME = "Fori44", PASSWORD = "******", COUNTRY_CODE = alf.GetRandomCountryId() }); companies.Add(new AirlineCompany { AIRLINE_NAME = "Jambo AirLine", USER_NAME = "Jambo27", PASSWORD = "******", COUNTRY_CODE = alf.GetRandomCountryId() }); companies.Add(new AirlineCompany { AIRLINE_NAME = "Ponnies", USER_NAME = "PonyTail21", PASSWORD = "******", COUNTRY_CODE = alf.GetRandomCountryId() }); companies.Add(new AirlineCompany { AIRLINE_NAME = "Sea Esta", USER_NAME = "Beach99", PASSWORD = "******", COUNTRY_CODE = alf.GetRandomCountryId() }); companies.Add(new AirlineCompany { AIRLINE_NAME = "Rolland lines", USER_NAME = "Roll53", PASSWORD = "******", COUNTRY_CODE = alf.GetRandomCountryId() }); companies.Add(new AirlineCompany { AIRLINE_NAME = "Turkish AirLines", USER_NAME = "Turk131", PASSWORD = "******", COUNTRY_CODE = alf.GetRandomCountryId() }); companies.Add(new AirlineCompany { AIRLINE_NAME = "Kebaba Lines", USER_NAME = "Bikjs", PASSWORD = "******", COUNTRY_CODE = alf.GetRandomCountryId() }); companies.Add(new AirlineCompany { AIRLINE_NAME = "Ironia Air", USER_NAME = "airf64", PASSWORD = "******", COUNTRY_CODE = alf.GetRandomCountryId() }); return(companies); }
public List <AirlineCompany> AirlineCompnyApiWork() { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(airlineCompaniesUrl); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.GetAsync("").Result; if (response.IsSuccessStatusCode) { var dataObjects = response.Content.ReadAsAsync <IEnumerable <AirlineCompaniesAPI> >().Result; foreach (var airline in dataObjects) { airlines.Add(new AirlineCompany(airline.Airline_Name, airline.user_name, airline.password, airlineFacade.GetRandomCountryId())); } for (int i = 0; i < dataObjects.Count(); i++) { returnAirlines.Add(airlines[i]); } } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } return(returnAirlines); }