Esempio n. 1
0
        public AvailableTrips getAvailableRoutes(int sourceId, int destinationId, String dateOfJourney, String URL, String ConsumerKey, int ProviderID)
        {
            try
            {
                dateOfJourney = dateOfJourney.Split('-')[2] + "-" + dateOfJourney.Split('-')[1] + "-" + dateOfJourney.Split('-')[0];
                if (File.Exists(Path.Combine(HttpRuntime.AppDomainAppPath, "Routes\\" + dateOfJourney + ".xml")))
                {
                    DataSet ds = new DataSet();
                    ds.ReadXml(Path.Combine(HttpRuntime.AppDomainAppPath, "Routes\\" + dateOfJourney + ".xml"));
                    if (ds != null && ds.Tables.Count > 0 && ds.Tables["route"].Rows.Count > 0)
                    {
                        objAvailableTrips = new AvailableTrips();
                        DataView dv = ds.Tables["route"].DefaultView;
                        dv.RowFilter = "origin_id=" + sourceId + "and destination_id=" + destinationId;
                        foreach (DataRowView item in dv)
                        {
                            //add the routes that match with given source and destinations
                            if (int.Parse(item["origin_id"].ToString()) == sourceId && int.Parse(item["destination_id"].ToString()) == destinationId)
                            {
                                LJ.CLB.DTO.TripDetails objTripDetails = new DTO.TripDetails();
                                objTripDetails.providerName = "BITLA";
                                objTripDetails.arrivalTime = CalculateArrivalTime(item["dep_time"].ToString(), item["duration"].ToString());
                                objTripDetails.availableSeats = item["available_seats"].ToString();
                                //boardingTimes are fetched in seat layout
                                objTripDetails.busType = item["bus_type"].ToString();
                                //cancellationPolicy  is not valid for bitla
                                objTripDetails.cancellationPolicy = String.Empty;
                                objTripDetails.departureTime = item["dep_time"].ToString();
                                //droppingTimes are fetched in seat layout
                                objTripDetails.duration = item["duration"].ToString();
                                objTripDetails.fares = item["fare_str"].ToString();
                                objTripDetails.id = item["reservation_id"].ToString();
                                objTripDetails.partialCancellationAllowed = item["is_cancellable"].ToString();
                                objTripDetails.travels = item["travels"].ToString();
                                objTripDetails.sourceId = int.Parse(item["origin_id"].ToString());
                                objTripDetails.destinationId = int.Parse(item["destination_id"].ToString());
                                trip.Add(objTripDetails);
                            }
                        }

                    }
                    //ignore operator list
                    clsMasters obj = new clsMasters();
                    DataSet dsignore = obj.GetIgnoreList(ProviderID);
                    if (dsignore != null)
                    {
                        if (dsignore.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow row in dsignore.Tables[0].Rows)
                            {
                                trip = trip.Where(e => e.travels != row[3].ToString()).ToList();
                            }

                        }

                    }
                    foreach (var bt in trip)
                    {
                        LJ.CLB.DTO.TripDetails objTripDetails = new DTO.TripDetails();
                        objTripDetails.providerName = "BITLA";
                        objTripDetails.arrivalTime = CalculateArrivalTime(bt.departureTime.ToString(), bt.duration.ToString());
                        objTripDetails.availableSeats = bt.availableSeats.ToString();
                        //boardingTimes are fetched in seat layout
                        objTripDetails.busType = bt.busType.ToString();
                        //cancellationPolicy  is not valid for bitla
                        objTripDetails.cancellationPolicy = String.Empty;
                        objTripDetails.departureTime = bt.departureTime.ToString();
                        //droppingTimes are fetched in seat layout
                        objTripDetails.duration = bt.duration.ToString() + " hrs";
                        objTripDetails.fares = bt.fares.ToString();
                        objTripDetails.id = bt.id.ToString();
                        objTripDetails.partialCancellationAllowed = bt.partialCancellationAllowed.ToString();
                        objTripDetails.travels = bt.travels.ToString();
                        objTripDetails.sourceId = int.Parse(bt.sourceId.ToString());
                        objTripDetails.destinationId = int.Parse(bt.destinationId.ToString());
                        objAvailableTrips.Add(objTripDetails);
                    }
                }

                return objAvailableTrips;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public AvailableTrips getTripListV2(int sourceId, int destinationId, String dateOfJourney, String URL, String ConsumerKey, String ConsumerSecret, int ProviderID)
        {
            try
            {

                //return "";
                //Convert dd-mm-yyyy format to API compatible format dd/mm/yyyy
                dateOfJourney = dateOfJourney.Replace('-', '/');
                client = new TGTravelServiceClient("TGSWS", URL);
                TripWithArrival response = client.getTripListV2(ConsumerKey, ConsumerSecret, sourceId.ToString(), destinationId.ToString(), dateOfJourney);
                AvailableTrips objAvailableTrips = null;
                if (response != null && response.tripList != null && response.tripList.Length > 0)
                {
                    objAvailableTrips = new AvailableTrips();
                    #region Loop each trip and add trip details to availabletrips

                    //ignore operator list

                    List<object> oo = new List<object>();
                    clsMasters obj = new clsMasters();
                    DataSet ds = obj.GetIgnoreList(ProviderID);
                    if (ds != null)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            AvailableFlights = response.tripList.ToList();
                            foreach (DataRow row in ds.Tables[0].Rows)
                            {

                                AvailableFlights = AvailableFlights.Where(e => e.provider != row[3].ToString()).ToList();

                            }
                        }
                        else
                        {
                            AvailableFlights = response.tripList.ToList();
                        }
                    }

                    //end ignore operator list
                    // List<TripWithArrivalDTO> AvailableFlights = response.tripList.Where(e => e.provider.Except(studentQuery).ToList();

                    foreach (TripWithArrivalDTO item in AvailableFlights)
                    {
                        //if (item.provider == "SVR Tours &  Travels")
                        //{
                        //}

                        LJ.CLB.DTO.TripDetails objTripDetails = new DTO.TripDetails();
                        objTripDetails.providerName = "TICKETGOOSE";
                        //remove seconds and make it to 12hr format
                        if (item.arrivalTime != null)
                        {
                            if (int.Parse(item.arrivalTime.Split(':')[0]) < 12) objTripDetails.arrivalTime = item.arrivalTime.Split(':')[0] + ':' + item.arrivalTime.Split(':')[1] + " AM";
                            else objTripDetails.arrivalTime = (int.Parse(item.arrivalTime.Split(':')[0]) - 12).ToString() + ':' + item.arrivalTime.Split(':')[1] + " PM";
                        }
                        else
                            objTripDetails.arrivalTime = "-";

                        objTripDetails.availableSeats = item.availableSeats;

                        //objTripDetails.boardingTimes = JsonConvert.SerializeObject(item.pickUpPointList);
                        objTripDetails.busType = item.type;
                        //cancellationPolicy  is not valid for ticketgoose
                        objTripDetails.cancellationPolicy = String.Empty;

                        //remove seconds and make it to 12hr format
                        if (item.departureTime != null)
                        {
                            if (int.Parse(item.departureTime.Split(':')[0]) < 12) objTripDetails.departureTime = item.departureTime.Split(':')[0] + ':' + item.departureTime.Split(':')[1] + " AM";
                            else objTripDetails.departureTime = (int.Parse(item.departureTime.Split(':')[0]) - 12).ToString() + ':' + item.departureTime.Split(':')[1] + " PM";
                        }

                        //objTripDetails.droppingTimes = String.Empty;

                        if (item.departureTime != null && item.arrivalTime != null)
                            //objTripDetails.duration = Duration(objTripDetails.departureTime, objTripDetails.arrivalTime);
                            objTripDetails.duration = Duration(objTripDetails.departureTime, objTripDetails.arrivalTime);
                        if (objTripDetails.duration == null)
                        {
                            objTripDetails.duration = "-";
                        }
                        objTripDetails.fares = item.fare;
                        objTripDetails.id = item.scheduleId;
                        //partialCancellationAllowed is not valid for ticketkgoose
                        objTripDetails.partialCancellationAllowed = String.Empty;
                        objTripDetails.travels = item.provider;
                        objTripDetails.sourceId = sourceId;
                        objTripDetails.destinationId = destinationId;
                        objAvailableTrips.Add(objTripDetails);

                    }
                    #endregion
                }

                return objAvailableTrips;

            }
            catch (Exception ex)
            {
                return null;
            }
        }