Ejemplo n.º 1
0
        /// <summary>
        /// Adds the search result for connecting flights in the schedule
        /// </summary>
        /// <param name="searchInformation"></param>
        /// <param name="scheduleCollection"></param>
        /// <param name="result"></param>
        /// <exception cref="ConnectingFlightsNotAvailableException">Throws the exception when connecting flights are not available for given search information</exception>
        private void AddSearchResultForConnectingFlights(SearchInfo searchInformation, Schedules scheduleCollection, SearchResult result)
        {
            Schedules      connectingSchedules = null;
            bool           isConnecting        = false;
            TravelSchedule scheduleForTravel   = null;

            foreach (Schedule s in scheduleCollection)
            {
                connectingSchedules = null;
                isConnecting        = false;

                if (s.RouteInfo.FromCity.CityId == searchInformation.FromCity.CityId && s.RouteInfo.ToCity.CityId != searchInformation.ToCity.CityId)
                {
                    //Create connecting schedules collection and add the current schedule
                    connectingSchedules = new Schedules();
                    connectingSchedules.AddSchedule(s);

                    isConnecting = FindFlightSchedule(searchInformation.ToCity, scheduleCollection, s, connectingSchedules);
                    if (isConnecting)
                    {
                        bool isValid = false;

                        foreach (Schedule sch in connectingSchedules)
                        {
                            isValid = CheckIfScheduleIsValid(s, searchInformation);
                            if (!isValid)
                            {
                                break;
                            }
                        }

                        if (isValid)
                        {
                            //Create a new TravelSchedule
                            scheduleForTravel = CreateTravelSchedule(ScheduleType.Connecting);

                            //Add schedules to Travel Schedule
                            AddScheduleForTravel(scheduleForTravel, connectingSchedules);

                            //Compute total cost for the Travel Schedule
                            CalculateTotalCostForTravel(scheduleForTravel);

                            //Add the travel schedule defined to the search result
                            AddTravelScheduleToResult(scheduleForTravel, result);
                        }
                    }
                }
            }

            if (scheduleForTravel == null)
            {
                throw new ConnectingFlightsNotAvailableException("Connecting Flights Not Available");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the connecting flight schedules for a given schedule
        /// </summary>
        /// <param name="toCity"></param>
        /// <param name="schCollection"></param>
        /// <param name="s"></param>
        /// <param name="connectingSchedules"></param>
        /// <returns>Returns the status of whether the connecting schedules were found or not</returns>
        private bool FindFlightSchedule(City toCity, Schedules schCollection, Schedule s, Schedules connectingSchedules)
        {
            bool isConnecting = false;

            foreach (Schedule cs in schCollection)
            {
                if (cs.RouteInfo.FromCity.CityId == s.RouteInfo.ToCity.CityId)
                {
                    connectingSchedules.AddSchedule(cs);

                    if (cs.RouteInfo.ToCity.CityId == toCity.CityId)
                    {
                        isConnecting = true;
                        break;
                    }
                    else
                    {
                        isConnecting = FindFlightSchedule(toCity, schCollection, cs, connectingSchedules);
                    }
                }
            }

            return(isConnecting);
        }
Ejemplo n.º 3
0
        ///// <summary>
        ///// Gets the flight schedules for the search made by the user
        ///// </summary>
        ///// <param name="searchInformation"></param>
        ///// <exception cref="SearchFlightDAOException">Throws SearchFlightDAOException if flights are not available or if there is any other exception</exception>
        ///// <returns>Returns the schedules for the given search - which is a custom collection</returns>
        //public Schedules SearchForFlight(SearchInfo searchInformation)
        //{
        //    Schedules schCollection = null;

        //    try
        //    {
        //        Database db = GetDatabaseConnection();
        //        TimeSpan ts;
        //        int hours = 0;
        //        int minutes = 0;
        //        int seconds = 0;

        //        using (IDataReader reader = db.ExecuteReader("GetFlightSchedules", searchInformation.FromCity.CityId, searchInformation.ToCity.CityId, (int)searchInformation.Class))
        //        {
        //            schCollection = new Schedules();
        //            while (reader.Read())
        //            {
        //                Schedule sch = new Schedule();
        //                sch.ID = Convert.ToInt64(reader["ScheduleId"]);

        //                hours = Convert.ToDateTime(reader["ArrivalTime"]).Hour;
        //                minutes = Convert.ToDateTime(reader["ArrivalTime"]).Minute;
        //                seconds = Convert.ToDateTime(reader["ArrivalTime"]).Second;
        //                ts = new TimeSpan(hours, minutes, seconds);
        //                sch.ArrivalTime = ts;

        //                hours = Convert.ToDateTime(reader["DepartureTime"]).Hour;
        //                minutes = Convert.ToDateTime(reader["DepartureTime"]).Minute;
        //                seconds = Convert.ToDateTime(reader["DepartureTime"]).Second;
        //                ts = new TimeSpan(hours, minutes, seconds);
        //                sch.DepartureTime = ts;

        //                sch.DurationInMins = Convert.ToInt16(reader["DurationInMins"]);
        //                sch.IsActive = Convert.ToBoolean(reader["IsActive"]);

        //                Airline objAirlineForFlight = new Airline();
        //                objAirlineForFlight.Code = reader["AirlineCode"].ToString();
        //                objAirlineForFlight.Id = Convert.ToInt16(reader["AirlineId"]);
        //                objAirlineForFlight.Logo = reader["AirlineLogo"].ToString();
        //                objAirlineForFlight.Name = reader["AirlineName"].ToString();

        //                Flight objFlight = new Flight();
        //                objFlight.ID = Convert.ToInt16(reader["FlightId"]);
        //                objFlight.Name = reader["FlightName"].ToString();
        //                objFlight.AirlineForFlight = objAirlineForFlight;
        //                FlightClass fc = new FlightClass();
        //                fc.ClassInfo = (TravelClass)(Convert.ToInt16(reader["ClassId"]));
        //                fc.NoOfSeats = Convert.ToInt32(reader["NoOfSeats"]);
        //                objFlight.AddClass(fc);

        //                FlightCost objFlightCost = new FlightCost();
        //                objFlightCost.CostPerTicket = Convert.ToDecimal(reader["CostPerTicket"]);
        //                objFlightCost.Class = (TravelClass)(Convert.ToInt16(reader["ClassId"]));

        //                City objFromCity = new City();
        //                objFromCity.CityId = Convert.ToInt64(reader["FromCityId"]);
        //                objFromCity.Name = reader["FromCityName"].ToString();

        //                City objToCity = new City();
        //                objToCity.CityId = Convert.ToInt64(reader["ToCityId"]);
        //                objToCity.Name = reader["ToCityName"].ToString();

        //                Route objRoute = new Route();
        //                objRoute.DistanceInKms = Convert.ToDouble(reader["DistanceInKms"]);
        //                objRoute.FromCity = objFromCity;
        //                objRoute.ToCity = objToCity;

        //                sch.FlightInfo = objFlight;
        //                sch.AddFlightCost(objFlightCost);
        //                sch.RouteInfo = objRoute;

        //                schCollection.AddSchedule(sch);
        //            }
        //        }
        //    }
        //    catch (Common.ConnectToDatabaseException ex)
        //    {
        //        throw new SearchFlightDAOException("Unable to Search for Flight", ex);
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new SearchFlightDAOException("Unable to Search for Flight", ex);
        //    }

        //    return schCollection;
        //}
        #endregion

        #region Method to get the flights for the search made by a user
        /// <summary>
        /// Gets the flight schedules for the search made by the user
        /// </summary>
        /// <param name="searchInformation"></param>
        /// <exception cref="SearchFlightDAOException">Throws SearchFlightDAOException if flights are not available or if there is any other exception</exception>
        /// <returns>Returns the schedules for the given search - which is a custom collection</returns>
        public Schedules SearchForFlight(SearchInfo searchInformation)
        {
            Schedules schCollection = null;

            try
            {
                IDbConnection conn = this.GetConnection();
                conn.Open();
                TimeSpan ts;
                int      hours   = 0;
                int      minutes = 0;
                int      seconds = 0;

                IDbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "GetFlightSchedules";
                cmd.CommandType = CommandType.StoredProcedure;

                IDataParameter fromCityId = cmd.CreateParameter();
                fromCityId.ParameterName = "FromCityId";
                fromCityId.Value         = searchInformation.FromCity.CityId;

                IDataParameter toCityId = cmd.CreateParameter();
                toCityId.ParameterName = "ToCityId";
                toCityId.Value         = searchInformation.ToCity.CityId;

                IDataParameter classId = cmd.CreateParameter();
                classId.ParameterName = "ClassId";
                classId.Value         = (int)searchInformation.Class;

                cmd.Parameters.Add(fromCityId);
                cmd.Parameters.Add(toCityId);
                cmd.Parameters.Add(classId);

                using (IDataReader reader = cmd.ExecuteReader())
                {
                    schCollection = new Schedules();
                    while (reader.Read())
                    {
                        Schedule sch = new Schedule();
                        sch.ID = Convert.ToInt64(reader["ScheduleId"]);

                        hours           = Convert.ToDateTime(reader["ArrivalTime"]).Hour;
                        minutes         = Convert.ToDateTime(reader["ArrivalTime"]).Minute;
                        seconds         = Convert.ToDateTime(reader["ArrivalTime"]).Second;
                        ts              = new TimeSpan(hours, minutes, seconds);
                        sch.ArrivalTime = ts;

                        hours             = Convert.ToDateTime(reader["DepartureTime"]).Hour;
                        minutes           = Convert.ToDateTime(reader["DepartureTime"]).Minute;
                        seconds           = Convert.ToDateTime(reader["DepartureTime"]).Second;
                        ts                = new TimeSpan(hours, minutes, seconds);
                        sch.DepartureTime = ts;

                        sch.DurationInMins = Convert.ToInt16(reader["DurationInMins"]);
                        sch.IsActive       = Convert.ToBoolean(reader["IsActive"]);

                        Airline objAirlineForFlight = new Airline();
                        objAirlineForFlight.Code = reader["AirlineCode"].ToString();
                        objAirlineForFlight.Id   = Convert.ToInt16(reader["AirlineId"]);
                        objAirlineForFlight.Logo = reader["AirlineLogo"].ToString();
                        objAirlineForFlight.Name = reader["AirlineName"].ToString();

                        Flight objFlight = new Flight();
                        objFlight.ID               = Convert.ToInt16(reader["FlightId"]);
                        objFlight.Name             = reader["FlightName"].ToString();
                        objFlight.AirlineForFlight = objAirlineForFlight;
                        FlightClass fc = new FlightClass();
                        fc.ClassInfo = (TravelClass)(Convert.ToInt16(reader["ClassId"]));
                        fc.NoOfSeats = Convert.ToInt32(reader["NoOfSeats"]);
                        objFlight.AddClass(fc);

                        FlightCost objFlightCost = new FlightCost();
                        objFlightCost.CostPerTicket = Convert.ToDecimal(reader["CostPerTicket"]);
                        objFlightCost.Class         = (TravelClass)(Convert.ToInt16(reader["ClassId"]));

                        City objFromCity = new City();
                        objFromCity.CityId = Convert.ToInt64(reader["FromCityId"]);
                        objFromCity.Name   = reader["FromCityName"].ToString();

                        City objToCity = new City();
                        objToCity.CityId = Convert.ToInt64(reader["ToCityId"]);
                        objToCity.Name   = reader["ToCityName"].ToString();

                        Route objRoute = new Route();
                        objRoute.DistanceInKms = Convert.ToDouble(reader["DistanceInKms"]);
                        objRoute.FromCity      = objFromCity;
                        objRoute.ToCity        = objToCity;

                        sch.FlightInfo = objFlight;
                        sch.AddFlightCost(objFlightCost);
                        sch.RouteInfo = objRoute;

                        schCollection.AddSchedule(sch);
                    }
                }
            }
            catch (Common.ConnectToDatabaseException ex)
            {
                throw new SearchFlightDAOException("Unable to Search for Flight", ex);
            }
            catch (Exception ex)
            {
                throw new SearchFlightDAOException("Unable to Search for Flight", ex);
            }

            return(schCollection);
        }