Esempio n. 1
0
        public override IAnswer execute()
        {
            Database.SeatRequest sr = new Database.SeatRequest ();
            Database.FlightRequest fr = new Database.FlightRequest ();

            List<Database.Seat> databaseSeats = new List<Database.Seat> ();

            List<Database.Flight> flights = fr.fetchFlightFromCodeAndStartDate (flight.Template.Code, flight.StartDate);
            if (flights.Count != 1) {
                throw new Exception("No (unique) flight found with code " + flight.Template.Code + " and start date " + flight.StartDate);
            }
            int flightID =  flights[0].ID;

            if (seatClass != null) {
                Database.ClassRequest cr = new Database.ClassRequest ();
                List<Database.Class> classes = cr.fetchClassFromName (seatClass.Name);
                if(classes.Count != 1){
                    throw new Exception("No (unique) class found with name " + seatClass.Name);
                }
                int classID =  classes[0].ID;

                databaseSeats = sr.fetchSeatFromFlighAndClass (flightID, classID);
            } else {
                databaseSeats = sr.fetchSeatFromFlight (flightID);
            }

            List<Seat> seats = new List<Seat>();
            Database.ClassRequest clr = new Database.ClassRequest();
            foreach (Database.Seat s in databaseSeats) {
                SeatClass sc = new SeatClass(clr.fetchFromID(s.class_)[0].name);
                seats.Add(new Seat(sc, s.number));
            }

            return new AnswerGetSeats(seats);
        }
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;
        }