Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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;
        }