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.Class class_ = new Database.Class(SeatClass.Name);
            AnswerAdd aa = new AnswerAdd();

            try{
                class_.insert();
            } catch(Exception e){
                aa = new AnswerAdd(e.Message);
            }

            return aa;
        }
        public override IAnswer execute()
        {
            Database.Passenger passenger = new Database.Passenger (this.Passenger.Name);
            AnswerAdd aa = new AnswerAdd ();

            try {
                passenger.insert();
            } catch (Exception e) {
                aa = new AnswerAdd(e.Message);
            }

            return aa;
        }
        public override IAnswer execute()
        {
            Database.Country c = new Database.Country(this.Country.Name);

            AnswerAdd aa = new AnswerAdd();
            try{
                c.insert();
            } catch(Exception e){
                aa = new AnswerAdd(e.Message);
            }

            return aa;
        }
        public override IAnswer execute()
        {
            Database.FlightRequest fr = new Database.FlightRequest ();
            Database.PassengerRequest pr = new Database.PassengerRequest ();
            Database.SeatRequest sr = new Database.SeatRequest ();
            Database.ClassRequest cr = new Database.ClassRequest ();
            Database.AirplaneRequest ar = new Database.AirplaneRequest ();

            List<Database.Class> classes = cr.fetchClassFromName (this.Booking.Seat.SeatClass.Name);
            if (classes.Count != 1) {
                return new AnswerAdd ("No (unique) class found with name " + this.Booking.Seat.SeatClass.Name);
            }
            int classID = classes [0].ID;

            List<Database.Flight> flights = fr.fetchFlightFromCodeAndStartDate (code: this.Booking.Flight.Template.Code, startDate: this.Booking.Flight.StartDate);
            if (flights.Count != 1) {
                return new AnswerAdd("No (unique) flight found with code " + this.Booking.Flight.Template.Code + " at " + this.Booking.Flight.StartDate);
            }
            Database.Flight flight = flights[0];
            int flightID = flight.ID;

            List<Database.Airplane> airplanes = ar.fetchFromID (flight.airplane);
            int airplaneID = airplanes[0].ID;

            List<Database.Seat> seats = sr.fetchSeatFromClassNumberAndAirplane (class_: classID, number: this.Booking.Seat.Number, airplane: airplaneID);
            if (seats.Count != 1) {
                return new AnswerAdd ("No (unique) seat found with number " + this.Booking.Seat.Number + " from class " + this.Booking.Seat.SeatClass.Name);
            }
            int seatID = seats [0].ID;

            List<Database.Passenger> passengers = pr.fetchPassengerFromName (this.Booking.Passenger.Name);
            if (passengers.Count != 1) {
                return new AnswerAdd ("No (unique) passenger found with name " + this.Booking.Passenger.Name);
            }
            int passengerID = passengers [0].ID;

            Database.Booking booking = new Database.Booking (flight: flightID, passenger: passengerID, seat: seatID);
            AnswerAdd aa = new AnswerAdd ();

            try {
                booking.insert();
            } catch (Exception e) {
                aa = new AnswerAdd(e.Message);
            }

            return aa;
        }
        public override IAnswer execute()
        {
            if (this.Airline.Name == null) {
                return new AnswerAdd("The name of the airline isn't set");
            }

            Database.Airline airline = new Database.Airline(code: this.Airline.Code, name: this.Airline.Name);
            AnswerAdd aa = new AnswerAdd();

            try{
                airline.insert();
            } catch(Exception e){
                aa = new AnswerAdd(e.Message);
            }

            return aa;
        }
        public override IAnswer execute()
        {
            List<int> seats = new List<int> ();
            Database.SeatRequest sr = new Database.SeatRequest ();
            Database.ClassRequest cr = new Database.ClassRequest ();
            bool newSeats = false;

            if (this.Airplane.Seats == null) {
                return new AnswerAdd("The seats of the airplane aren't set");
            }

            foreach (Seat s in this.Airplane.Seats) {
                List<Database.Class> classes = cr.fetchClassFromName (s.SeatClass.Name);
                if(classes.Count != 1){
                    return new AnswerAdd("No (unique) class found with name " + s.SeatClass.Name);
                }
                int classID =  classes[0].ID;

                List<Database.Seat> databaseSeats = sr.fetchSeatFromClassAndNumber (class_: classID, number: s.Number);
                if(databaseSeats.Count == 0){
                    Database.Seat s_ = new Database.Seat(classID, s.Number, -1);
                    try {
                        s_.insert();
                    } catch (Exception e){
                        return new AnswerAdd(e.Message);
                    }
                    newSeats = true;
                    databaseSeats = sr.fetchSeatFromClassNumberAndAirplane (class_: classID, number: s.Number, airplane: -1);
                }
                int seatID =  databaseSeats[0].ID;
                seats.Add (seatID);
            }

            Database.Airplane airplane = new Database.Airplane (type: this.Airplane.Type, seat: seats, code: this.Airplane.Code);
            AnswerAdd aa = new AnswerAdd ();
            try {
                int airplaneID = airplane.insert();
                if (newSeats){
                    sr.updateSeats(airplaneID);
                }
            } catch (Exception e) {
                aa = new AnswerAdd(e.Message);
            }

            return aa;
        }
Example #8
0
        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;
        }
        public override IAnswer execute()
        {
            string airlineCode = "";
            string digits = "";
            Database.Util.split(this.FlightTemplate.Code, ref airlineCode, ref digits);

            Database.AirlineRequest ar = new Database.AirlineRequest ();
            List<Database.Airline> airlines = ar.fetchAirlineFromCode (airlineCode);
            if (airlines.Count () != 1) {
                return new AnswerAdd("A (unique) airline with code " + airlineCode + " couldn't be found");
            }
            int airlineID = airlines[0].ID;

            Database.FlightTemplate template = new Database.FlightTemplate(airlineID, this.FlightTemplate.digits);
            AnswerAdd aa = new AnswerAdd();

            try{
                template.insert();
            } catch(Exception e){
                aa = new AnswerAdd(e.Message);
            }

            return aa;
        }
Example #10
0
        public override IAnswer execute()
        {
            Database.LocationRequest lr = new Database.LocationRequest ();
            Database.AirlineRequest ar = new Database.AirlineRequest ();
            Database.AirplaneRequest apr = new Database.AirplaneRequest ();
            Database.FlightTemplateRequest ftr = new Database.FlightTemplateRequest ();

            string airlineCode = "";
            string digits = "";
            Database.Util.split(this.Flight.Template.Code, ref airlineCode, ref digits);

            if (this.Flight.StartAirport == null) {
                return new AnswerAdd("The start airport of the flights isn't set");
            }

            List<Database.Location> locations = lr.fetchLocationFromAirports (new Database.Airport (code: this.Flight.StartAirport.Code), new Database.Airport (code: this.Flight.DestinationAirport.Code));
            if (locations.Count () == 0) {
                Database.AirportRequest airportRequest = new Database.AirportRequest();
                List<Database.Airport> airports = airportRequest.fetchAirportFromCode(this.Flight.StartAirport.Code);
                if(airports.Count() != 1){
                    return new AnswerAdd("Couldn't find a (unique) airport with code " + this.Flight.StartAirport.Code);
                }
                int airport1ID = airports[0].ID;

                airports = airportRequest.fetchAirportFromCode(this.Flight.DestinationAirport.Code);
                if(airports.Count() != 1){
                    return new AnswerAdd("Couldn't find a (unique) airport with code " + this.Flight.DestinationAirport.Code);
                }
                int airport2ID = airports[0].ID;

                Database.Location location = new Database.Location(airport1ID, airport2ID, this.Flight.distance);
                try{
                    location.insert();
                } catch(Exception e){
                    return new AnswerAdd(e.Message);
                }
                locations = lr.fetchLocationFromAirports (new Database.Airport (code: this.Flight.StartAirport.Code), new Database.Airport (code: this.Flight.DestinationAirport.Code));
            }
            int locationID = locations [0].ID;

            List<Database.Airline> airlines = ar.fetchAirlineFromCode (airlineCode);
            if (airlines.Count () != 1) {
                return new AnswerAdd ("Couldn't find a (unique) airline with code " + airlineCode);
            }
            int airlineID = airlines [0].ID;

            List<Database.Airplane> airplanes = apr.fetchAirplaneFromCode (this.Flight.Airplane.Code);
            if (airplanes.Count () != 1) {
                return new AnswerAdd ("Couldn't find a (unique) airplane with code " + this.Flight.Airplane.Code);
            }
            int airplaneID = airplanes [0].ID;

            List<Database.FlightTemplate> templates = ftr.fetchTemplateFromAirlineAndDigits(airlineID, digits);
            if (templates.Count () != 1) {
                return new AnswerAdd("Couldn't find a (unique) template from airline " + airlines[0].code + " with digits " + this.Flight.Template.digits);
            }
            int templateID =  templates [0].ID;

            Database.Flight flight = new Database.Flight (locationID, airlineID, this.Flight.StartDate, this.Flight.EndDate, airplaneID, templateID, this.Flight.TravelTime);
            AnswerAdd aa = new AnswerAdd ();
            try {
                flight.insert();
            } catch (Exception e) {
                aa = new AnswerAdd(e.Message);
            }

            return aa;
        }