public void UpdateFlight(LoginToken <AirlineCompany> token, Flight flight) { CheckToken(token); flightDAO.Update(flight); Logger.Log(LogLevel.Info, $"The airline company '{token.User.Name}' has updated flight {flight.Id}."); }
public void Remove(int id) { TryCatchDatabaseFunction((conn) => { // Checks if an airline company with that ID exists: string query = $"SELECT * FROM AirlineCompanies WHERE AirlineCompanies.ID = {id}"; MySqlCommand cmd = new MySqlCommand(query, conn); MySqlDataReader reader = cmd.ExecuteReader(); AirlineCompany airlineCompany = new AirlineCompany(); while (reader.Read()) { airlineCompany.Id = Convert.ToInt32(reader[0]); } reader.Close(); if (airlineCompany.Id == 0) { throw new AirlineCompanyNotFoundException($"Airline Company with ID: {id} doesn't exist"); } // Deleting all airline's flights: query = $"SELECT * FROM Flights WHERE Flights.AIRLINE_COMPANY_ID = {id}"; cmd = new MySqlCommand(query, conn); reader = cmd.ExecuteReader(); List <Flight> flights = new List <Flight>(); while (reader.Read()) { Flight flight = new Flight(); flight.Id = Convert.ToInt32(reader[0]); flights.Add(flight); } reader.Close(); foreach (Flight flight in flights) { query = $"DELETE FROM Tickets WHERE Tickets.FLIGHT_ID = {flight.Id}"; cmd = new MySqlCommand(query, conn); cmd.ExecuteNonQuery(); query = $"DELETE FROM Flights WHERE Flights.ID = {flight.Id}"; cmd = new MySqlCommand(query, conn); cmd.ExecuteNonQuery(); } // Deleting the airline: query = $"DELETE FROM AirlineCompanies WHERE AirlineCompanies.ID = {id}"; cmd = new MySqlCommand(query, conn); cmd.ExecuteNonQuery(); }); }
public void CreateFlight(LoginToken <AirlineCompany> token, Flight flight) { CheckToken(token); flightDAO.Add(flight); Logger.Log(LogLevel.Info, $"The airline company '{token.User.Name}' created a new flight."); }