/// <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 customers to the database.
        /// </summary>
        /// <param name="customers"></param>
        public void AddCustomersToDB(int customers)
        {
            for (int i = 0; i < customers; i++)
            {
                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)
                {
                    FlightCenterProject.CustomerDAOMSSQL customerDAOMSSQL = new FlightCenterProject.CustomerDAOMSSQL();

                    WebResult dataObjects = response.Content.ReadAsAsync <WebResult>().Result;

                    string phoneNum   = dataObjects.results[0].phone;
                    string creditCard = dataObjects.results[0].cell;//replace the credit card number.
                    string userName   = dataObjects.results[0].login.username;
                    string pass       = dataObjects.results[0].login.password;
                    string address    = dataObjects.results[0].location.city;
                    string firstName  = dataObjects.results[0].name.first;
                    string lastName   = dataObjects.results[0].name.last;

                    FlightCenterProject.Customer customer = new FlightCenterProject.Customer(firstName, lastName, userName, pass, address, phoneNum, creditCard);

                    customerDAOMSSQL.Add(customer);
                }
                else
                {
                    Debug.Write((int)response.StatusCode, response.ReasonPhrase);
                }

                client.Dispose();

                Percent += Convert.ToInt32(1.0 / Total * 100);

                Message = $"{i + 1}/{customers} Customers created";
            }
        }