public FlightSuggestions SuggestFlights([Validated("tripValidator")] Trip trip)
        {
            #region Sanity Check

            if (trip == null)
            {
                throw new ArgumentNullException("trip", "The 'trip' argument is required.");
            }

            #endregion

            Aircraft outboundAircraft, returnAircraft;
            bool     transAtlantic = trip.StartingFrom.AirportCode == "LHR" || trip.ReturningFrom.AirportCode == "LHR";
            if (transAtlantic)
            {
                outboundAircraft = aircraftDao.GetAircraft(2);
                returnAircraft   = aircraftDao.GetAircraft(2);
            }
            else
            {
                outboundAircraft = aircraftDao.GetAircraft(1);
                returnAircraft   = aircraftDao.GetAircraft(3);
            }
            Airport from = airportDao.GetAirport(trip.StartingFrom.AirportCode);
            Airport to   = airportDao.GetAirport(trip.ReturningFrom.AirportCode);

            FlightCollection outboundFlights = new FlightCollection();
            outboundFlights.Add(new Flight("UA 0123", from, to, outboundAircraft, trip.StartingFrom.Date.AddHours(6.5)));
            outboundFlights.Add(new Flight("AA 2367", from, to, outboundAircraft, trip.StartingFrom.Date.AddHours(10)));
            outboundFlights.Add(new Flight("SW 6534", from, to, outboundAircraft, trip.StartingFrom.Date.AddHours(15.75)));
            outboundFlights.Add(new Flight("CO 0054", from, to, outboundAircraft, trip.StartingFrom.Date.AddHours(19.25)));

            FlightCollection returnFlights = new FlightCollection();
            returnFlights.Add(new Flight("CO 0112", to, from, returnAircraft, trip.ReturningFrom.Date.AddHours(9)));
            returnFlights.Add(new Flight("UA 0230", to, from, returnAircraft, trip.ReturningFrom.Date.AddHours(12.3)));
            returnFlights.Add(new Flight("AA 2234", to, from, returnAircraft, trip.ReturningFrom.Date.AddHours(21.5)));

            if (trip.Mode == TripMode.RoundTrip)
            {
                return(new FlightSuggestions(outboundFlights, returnFlights));
            }
            else
            {
                return(new FlightSuggestions(outboundFlights, NoSuggestions));
            }
        }
Ejemplo n.º 2
0
        public void ProcessRow(IDataReader dataReader)
        {
            int      flightId     = dataReader.GetInt32(0);
            string   flightNumber = dataReader.GetString(1);
            Aircraft aircraft     = aircraftDao.GetAircraft(dataReader.GetInt32(2));

            //TODO: Load cabins from the database
            Cabin[] cabins = aircraft.Cabins;

            Flight flight = new Flight(flightId, flightNumber, origin, destination, aircraft, departureDate, cabins);

            flights.Add(flight);
        }
Ejemplo n.º 3
0
        public FlightCollection GetFlights(Airport origin, Airport destination, DateTime departureDate)
        {
            #region Sanity Checks
            AssertUtils.ArgumentNotNull(origin, "origin");
            AssertUtils.ArgumentNotNull(destination, "destination");
            #endregion

            FlightCollection flights = new FlightCollection();


            IDbParametersBuilder builder = new DbParametersBuilder(DbProvider);
            builder.Create().Name("departureDate").Type(DbType.Date).Value(departureDate);
            builder.Create().Name("departureAirport").Type(DbType.Int32).Value(origin.Id);
            builder.Create().Name("destinationAirport").Type(DbType.Int32).Value(destination.Id);

#if NET_2_0
            AdoTemplate.QueryWithRowCallbackDelegate(CommandType.Text, FlightsQuery,
                                                     delegate(IDataReader dataReader)
            {
                int flightId        = dataReader.GetInt32(0);
                string flightNumber = dataReader.GetString(1);
                Aircraft aircraft   = aircraftDao.GetAircraft(dataReader.GetInt32(2));

                //TODO: Load cabins from the database
                Cabin[] cabins = aircraft.Cabins;

                Flight flight = new Flight(flightId, flightNumber, origin, destination, aircraft, departureDate, cabins);
                flights.Add(flight);
            },


                                                     builder.GetParameters());
#else
            AdoTemplate.QueryWithRowCallback(CommandType.Text, FlightsQuery,
                                             new FlightRowCallback(flights, aircraftDao, origin, destination, departureDate),
                                             builder.GetParameters());
#endif


            /*
             * IDbCommand command = GetCommand(FlightsQuery);
             * using(new ConnectionManager(command.Connection))
             * {
             *  SetFlightQueryParameters(command, departureDate, origin.Id, destination.Id);
             *  using (SqlDataReader reader = (SqlDataReader) command.ExecuteReader())
             *  {
             *      while(reader.Read())
             *      {
             *          int flightId = reader.GetInt32(0);
             *          string flightNumber = reader.GetString(1);
             *          Aircraft aircraft = aircraftDao.GetAircraft(reader.GetInt32(2));
             *
             *          //TODO: Load cabins from the database
             *          Cabin[] cabins = aircraft.Cabins;
             *
             *          Flight flight = new Flight(flightId, flightNumber, origin, destination, aircraft, departureDate, cabins);
             *          flights.Add(flight);
             *      }
             *  }
             * }
             */
            return(flights);
        }