public override IAnswer execute() { List<Database.Airport> airports = new List<Database.Airport>(); if (this.City != null) { airports = executeOnCity(); } else if (this.Country != null) { airports = executeOnCountry(); } Database.AirlineRequest alr = new Database.AirlineRequest(); List<Airport> resultAirports = new List<Airport>(); foreach(Database.Airport a in airports){ Database.CityRequest cir = new Database.CityRequest(); Database.CountryRequest cor = new Database.CountryRequest(); Database.City ci = cir.fetchFromID(a.city)[0]; Database.Country co = cor.fetchFromID(a.country)[0]; Country country = new Country(co.name); List<Airline> airlines = new List<Airline>(); foreach(int airline in a.company){ Database.Airline al = alr.fetchFromID(airline)[0]; airlines.Add(new Airline(Name: al.name, Code: al.code)); } resultAirports.Add(new Airport(Name: a.name, Code: a.code, City: new City(ci.name, country), Airlines: airlines)); } return new AnswerGetAirports(resultAirports); }
public override IAnswer execute() { Database.CountryRequest cor = new Database.CountryRequest (); Database.CityRequest cir = new Database.CityRequest (); if (this.Airport.City == null) { return new AnswerAdd("The city of the airport isn't set."); } List<Database.Country> countries = cor.fetchCountryFromName (this.Airport.City.Country.Name); if (countries.Count != 1) { return new AnswerAdd ("No (unique) country found with name " + this.Airport.City.Country.Name); } int countryID = countries [0].ID; List<Database.City> cities = cir.fetchFromNameAndCountry(this.Airport.City.Name, this.Airport.City.Country.Name); if (cities.Count != 1) { return new AnswerAdd("No (unique) city found with name " + this.Airport.City.Name + " in country " + this.Airport.City.Country.Name); } int cityID = cities[0].ID; AnswerAdd aa = new AnswerAdd (); Database.Airport airport = new Database.Airport (name: this.Airport.Name, code: this.Airport.Code, country: countryID, city: cityID); try { airport.insert(); } catch (Database.InvalidObjectException e){ aa = new AnswerAdd(e.Message); } catch (Exception e) { aa = new AnswerAdd(e.ToString()); } return aa; }
public override IAnswer execute() { Database.CountryRequest cr = new Database.CountryRequest (); List<Database.Country> countries = cr.fetchCountryFromName (this.City.Country.Name); if (countries.Count != 1) { return new AnswerAdd("No (unique) country found with name " + this.City.Country.Name); } int countryID = countries[0].ID; Database.City city = new Database.City (name: this.City.Name, country: countryID); AnswerAdd aa = new AnswerAdd(); try { city.insert (); } catch (Exception e) { aa = new AnswerAdd(e.Message); } return aa; }
private List<Flight> adapt(List<Database.Flight> dfs) { Database.FlightTemplateRequest ftr = new Database.FlightTemplateRequest(); Database.AirlineRequest alr = new Database.AirlineRequest(); Database.AirplaneRequest apr = new Database.AirplaneRequest(); Database.LocationRequest lr = new Database.LocationRequest(); Database.SeatRequest sr = new Database.SeatRequest(); Database.ClassRequest cr = new Database.ClassRequest(); Database.CountryRequest cor = new Database.CountryRequest(); Database.CityRequest cir = new Database.CityRequest(); Database.AirportRequest ar = new Database.AirportRequest(); List<Flight> fs = new List<Flight>(); foreach(Database.Flight f in dfs){ Database.FlightTemplate ft = ftr.fetchFromID(f.template)[0]; Database.Airline airline_ = alr.fetchFromID(ft.airline)[0]; Airline airline = new Airline(Name: airline_.name, Code: airline_.code); FlightTemplate template = new FlightTemplate(ft.digits, airline); Database.Location l = lr.fetchFromID(f.location)[0]; Database.Airport startAirport_ = ar.fetchFromID(l.start_airport)[0]; Database.Airport destinationAirport_ = ar.fetchFromID(l.destination_airport)[0]; Country startCountry = new Country(cor.fetchFromID(startAirport_.country)[0].name); Country destinationCountry = new Country(cor.fetchFromID(destinationAirport_.country)[0].name); City startCity = new City(cir.fetchFromID(startAirport_.city)[0].name, startCountry); City destinationCity = new City(cir.fetchFromID(destinationAirport_.city)[0].name, destinationCountry); Airport startAirport = new Airport(startAirport_.name, startAirport_.code, startCity); Airport destinationAirport = new Airport(destinationAirport_.name, destinationAirport_.code, destinationCity); Database.Airplane airplane_ = apr.fetchFromID(f.airplane)[0]; List<Seat> seats = new List<Seat>(); foreach(int s in airplane_.seat){ Database.Seat seat_ = sr.fetchFromID(s)[0]; Database.Class seatClass_ = cr.fetchFromID(seat_.class_)[0]; SeatClass seatClass = new SeatClass(seatClass_.name); seats.Add(new Seat(seatClass, seat_.number)); } Airplane airplane = new Airplane(airplane_.type, seats, airplane_.code); fs.Add(new Flight(template, f.start, f.end, startAirport, destinationAirport, airplane)); } return fs; }
private List<Database.Flight> executedOnCountry() { Database.CountryRequest cr = new Database.CountryRequest (); List<Database.Country> countries = cr.fetchCountryFromName (Country1.Name); if (countries.Count () != 1) { throw new Exception ("A (unique) country with name " + Country1.Name + " couldn't be found"); } Database.Country startCountry = countries [0]; countries = cr.fetchCountryFromName (Country2.Name); if (countries.Count () != 1) { throw new Exception("A (unique) country with name " + Country2.Name + " couldn't be found"); } Database.Country endCountry = countries [0]; return doDispatch(startCountry, endCountry); }