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; }
private List<Database.Flight> executeOnCity() { Database.CityRequest cr = new Database.CityRequest (); List<Database.City> cities = cr.fetchFromNameAndCountry (City1.Name, City1.Country.Name); if (cities.Count () != 1) { throw new Exception ("A (unique) city with name " + City1.Name + " and country " + City1.Country.Name + " couldn't be found"); } Database.City startCity = cities [0]; cities = cr.fetchFromNameAndCountry (City2.Name, City2.Country.Name); if (cities.Count () != 1) { throw new Exception("A (unique) city with name " + City2.Name + " and country " + City2.Country.Name + " couldn't be found"); } Database.City endCity = cities [0]; return doDispatch(startCity, endCity); }