/// <summary> /// Delete all the database. /// </summary> public void DeleteFromDB() { FlightCenterProject.CustomerDAOMSSQL customerDAOMSSQL = new FlightCenterProject.CustomerDAOMSSQL(); customerDAOMSSQL.RemoveAll(); FlightCenterProject.FlightDAOMSSQL flightDAOMSSQL = new FlightCenterProject.FlightDAOMSSQL(); flightDAOMSSQL.RemoveAll(); FlightCenterProject.AirlineCompanyDAOMSSQL airlineCompanyDAOMSSQL = new FlightCenterProject.AirlineCompanyDAOMSSQL(); airlineCompanyDAOMSSQL.RemoveAll(); FlightCenterProject.CountryDAOMSSQL countryDAOMSSQL = new FlightCenterProject.CountryDAOMSSQL(); countryDAOMSSQL.RemoveAll(); Message = "The entire database has been deleted"; }
/// <summary> /// Add random number of tickets for every customer that exist in the database. /// </summary> /// <param name="ticket"></param> /// <param name="customers"></param> public void AddTicketsToDB(int ticket, int customers) { FlightCenterProject.FlightDAOMSSQL flightDAOMSSQL = new FlightCenterProject.FlightDAOMSSQL(); IList <FlightCenterProject.Flight> flights = flightDAOMSSQL.GetAll(); FlightCenterProject.CustomerDAOMSSQL customerDAOMSSQL = new FlightCenterProject.CustomerDAOMSSQL(); IList <FlightCenterProject.Customer> customers2 = customerDAOMSSQL.GetAll(); try { if (ticket > 0 && (flights.Count == 0 || customers2.Count == 0)) { throw new YouNeedToHaveFlightsAndCustomersToGetTicketsException("You can not get tickets if you dont have flights or customrs"); } for (int i = 0; i < (ticket * customers); i++) { List <FlightCenterProject.Ticket> tickets = new List <FlightCenterProject.Ticket>(); long flightId = flights[rnd.Next(flights.Count)].Id; long customerId = customers2[rnd.Next(customers2.Count)].Id; bool ThereIsAlreadyATicket = false; foreach (var ticket1 in tickets) { if (ticket1.FlightId == flightId) { if (ticket1.CustomerId == customerId) { ThereIsAlreadyATicket = true; break; } } } if (ThereIsAlreadyATicket == false) { FlightCenterProject.TicketDAOMSSQL ticketDAOMSSQL = new FlightCenterProject.TicketDAOMSSQL(); FlightCenterProject.Ticket ticket1 = new FlightCenterProject.Ticket(flightId, customerId); ticketDAOMSSQL.Add(ticket1); } Percent += Convert.ToInt32(1.0 / Total * 100); Message = $"{i + 1}/{ticket * customers} Tickets created"; } }catch (YouNeedToHaveFlightsAndCustomersToGetTicketsException e) { Message = e.Message; } }
/// <summary> /// Add random number of flights for the airline companies that exist in the database. /// </summary> /// <param name="flights"></param> /// <param name="airlinesCom"></param> public void AddFlightsToDB(int flights, int airlinesCom) { FlightCenterProject.AirlineCompanyDAOMSSQL airlineCompany = new FlightCenterProject.AirlineCompanyDAOMSSQL(); IList <FlightCenterProject.AirlineCompany> airlines = airlineCompany.GetAll(); try { if (flights > 0 && airlines.Count == 0) { throw new YouNeedToPutNumberOfAirlinesException("You can not get flights if you dont have airlines"); } else { for (int i = 0; i < (flights * airlinesCom); i++) { long airlineId = airlines[rnd.Next(airlines.Count)].Id; FlightCenterProject.CountryDAOMSSQL cAOMSSQL = new FlightCenterProject.CountryDAOMSSQL(); IList <FlightCenterProject.Country> countries = cAOMSSQL.GetAll(); long originCountryCode = countries[rnd.Next(countries.Count)].Id; long destinationCountryCode = countries[rnd.Next(countries.Count)].Id; HttpClient client = new HttpClient(); client.BaseAddress = new Uri(URL1); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.GetAsync("").Result; if (response.IsSuccessStatusCode) { WebResult dataObjects = response.Content.ReadAsAsync <WebResult>().Result; DateTime departureTime = dataObjects.results[0].dob.date; DateTime landingTime = dataObjects.results[0].registered.date; DateTime DEPARTURE_TIME = new DateTime(departureTime.Year, departureTime.Month, departureTime.Day, departureTime.Hour, departureTime.Minute, departureTime.Second); DateTime LANDING_TIME = new DateTime(landingTime.Year, landingTime.Month, landingTime.Day, landingTime.Hour, landingTime.Minute, landingTime.Second); FlightCenterProject.FlightDAOMSSQL flightDAOMSSQL = new FlightCenterProject.FlightDAOMSSQL(); FlightCenterProject.Flight flight = new FlightCenterProject.Flight(airlineId, originCountryCode, destinationCountryCode, DEPARTURE_TIME, LANDING_TIME, rnd.Next(200)); flightDAOMSSQL.Add(flight); } else { Debug.Write((int)response.StatusCode, response.ReasonPhrase); } client.Dispose(); Percent += Convert.ToInt32(1.0 / Total * 100); Message = $"{i + 1}/{flights * airlinesCom} Flights created"; } } }catch (YouNeedToPutNumberOfAirlinesException e) { Message = e.Message; } }