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; } }
public AvailableTrips getAvailableTrips(int sourceId, int destinationId, String dateofjourney, String URL, String ConsumerKey, String ConsumerSecret) { dateofjourney = dateofjourney.Split('-')[2] + "-" + dateofjourney.Split('-')[1] + "-" + dateofjourney.Split('-')[0]; try { String strResponse = objService.getAvailableTrips(sourceId.ToString(), destinationId.ToString(), dateofjourney, URL, ConsumerKey, ConsumerSecret); DataSet ds = convertJsonStringToDataSet(strResponse); //Check if response is valid else return error message if (ds == null) { throw new Exception(strResponse); } AvailableTrips objAvailableTrips = null; if (ds != null && ds.Tables.Count > 0 && ds.Tables["availableTrips"].Rows.Count > 0) { objAvailableTrips = new AvailableTrips(); #region Loop each trip and add trip details to availabletrips foreach (DataRow item in ds.Tables["availableTrips"].Rows) { DTO.TripDetails objTripDetails = new DTO.TripDetails(); objTripDetails.boardingTimes = new BoardingDroppingPoints(); objTripDetails.droppingTimes = new BoardingDroppingPoints(); objTripDetails.providerName = "REDBUS"; objTripDetails.availableSeats = item["availableSeats"].ToString(); objTripDetails.busType = item["busType"].ToString(); objTripDetails.cancellationPolicy = item["cancellationPolicy"].ToString(); objTripDetails.departureTime = Time(item["departureTime"].ToString()); #region Boarding & Dropping Points //boarding points DataTable dtBP = ds.Tables["boardingTimes"].Clone(); DataRow[] drBPArray = ds.Tables["boardingTimes"].Select("availableTrips_Id = " + item["availableTrips_Id"].ToString()); foreach (DataRow drow in drBPArray) { String strBP = "";// objService.getBoardingPoint(drow["bpId"].ToString(), URL, ConsumerKey, ConsumerSecret); BoardingDroppingDetails bp = new BoardingDroppingDetails(drow["bpId"].ToString(), drow["location"].ToString(), Time(drow["time"].ToString())); if (strBP != String.Empty) { bp.address = (String)JObject.Parse(strBP)["address"]; bp.landmark = (String)JObject.Parse(strBP)["landmark"]; bp.name = (String)JObject.Parse(strBP)["name"]; } objTripDetails.boardingTimes.Add(bp); } //dropping points DataTable dtDP = ds.Tables["droppingTimes"].Clone(); DataRow[] drDPArray = ds.Tables["droppingTimes"].Select("availableTrips_Id = " + item["availableTrips_Id"].ToString()); foreach (DataRow drow in drDPArray) { String strDP = "";// objService.getBoardingPoint(drow["bpId"].ToString(), URL, ConsumerKey, ConsumerSecret); BoardingDroppingDetails dp = new BoardingDroppingDetails(drow["bpId"].ToString(), drow["location"].ToString(), Time(drow["time"].ToString())); if (strDP != String.Empty) { dp.address = (String)JObject.Parse(strDP)["address"]; dp.landmark = (String)JObject.Parse(strDP)["landmark"]; dp.name = (String)JObject.Parse(strDP)["name"]; } objTripDetails.boardingTimes.Add(dp); } #endregion //check if boarding and dropping times are same. If so, show '-' if (item["arrivalTime"].ToString() != item["departureTime"].ToString()) { objTripDetails.arrivalTime = Time(item["arrivalTime"].ToString()); objTripDetails.duration = Duration(objTripDetails.departureTime, objTripDetails.arrivalTime); } else objTripDetails.arrivalTime = objTripDetails.duration = "-"; if (ds.Tables["fares"] == null) objTripDetails.fares = item["fares"].ToString(); else objTripDetails.fares = ds.Tables["fares"].Rows[ds.Tables["availableTrips"].Rows.IndexOf(item)]["fares_text"].ToString(); objTripDetails.id = item["id"].ToString(); objTripDetails.partialCancellationAllowed = item["partialCancellationAllowed"].ToString(); objTripDetails.travels = item["travels"].ToString(); objTripDetails.sourceId = sourceId; objTripDetails.destinationId = destinationId; objAvailableTrips.Add(objTripDetails); } #endregion } return objAvailableTrips; } catch (Exception ex) { throw ex; } }
public AvailableTrips getAvailableServices(int sourceId, int destinationId, String dateOfJourney, String URL, String ConsumerKey, string providername) { //Convert mm-dd-yyyy format to API compatible format dd-mm-yyyy dateOfJourney = dateOfJourney.Split('-')[1] + "/" + dateOfJourney.Split('-')[0] + "/" + dateOfJourney.Split('-')[2]; try { requestBody = URL + "/server.aspx?Method=GetAvailableServices&TripType=" + 1 + "&SorceStationid=" + sourceId + "&DestinationStationid=" + destinationId + "&DateofJourney=" + dateOfJourney + "&DateOfReturn=" + dateOfJourney + "&Key=" + ConsumerKey; DataSet ds = convertXMLtoDataset(getJSONReponse(requestBody)); DataTable dtBuses = new DataTable(); dtBuses = ds.Tables[0]; AvailableTrips objAvailableTrips = new AvailableTrips(); if (dtBuses != null) { //foreach (DataRow dtRow in dtBuses.Rows) //{ if (dtBuses.TableName!="Respones"|| dtBuses.TableName=="Services") { for (int i = 0; i < dtBuses.Rows.Count; i++) { LJ.CLB.DTO.TripDetails objTripDetails = new DTO.TripDetails(); objTripDetails.providerName = providername; objTripDetails.boardingTimes = null;//String.Empty; objTripDetails.cancellationPolicy = String.Empty; objTripDetails.droppingTimes = null;//String.Empty; objTripDetails.sourceId = int.Parse(sourceId.ToString()); objTripDetails.destinationId = int.Parse(destinationId.ToString()); objTripDetails.partialCancellationAllowed = "false"; int Totalseats = Convert.ToInt32(dtBuses.Rows[i]["CAPACITY"].ToString()); int BookedSeats = Convert.ToInt32(dtBuses.Rows[i]["BOOKEDSEATS"].ToString()); int AvailableSeats = Totalseats - BookedSeats; objTripDetails.id = dtBuses.Rows[i]["SERVICE_ID"].ToString(); objTripDetails.travels = dtBuses.Rows[i]["NOTES"].ToString(); objTripDetails.departureTime = dtBuses.Rows[i]["START_TIME"].ToString(); objTripDetails.arrivalTime = dtBuses.Rows[i]["HALT_TIME"].ToString(); objTripDetails.fares = dtBuses.Rows[i]["Fare"].ToString(); objTripDetails.availableSeats = AvailableSeats.ToString(); objTripDetails.busType = dtBuses.Rows[i]["BUS_TYPE"].ToString(); objTripDetails.SeatLayoutId = dtBuses.Rows[i]["LAYOUT_ID"].ToString(); objTripDetails.duration = Duration(objTripDetails.departureTime, objTripDetails.arrivalTime); objAvailableTrips.Add(objTripDetails); } } // } } return objAvailableTrips; } catch (Exception ex) { throw ex; } }
/// <summary> /// Method for getting all the available buses based on source, destination and date of journey /// </summary> /// <param name="sourceId"></param> /// <param name="destinationId"></param> /// <param name="dateOfJourney"></param> /// <param name="seatCount"></param> /// <param name="seatType">seat/sleeper</param> /// <param name="URL"></param> /// <param name="ConsumerKey"></param> /// <returns></returns> public AvailableTrips getBusAvailability(int sourceId, int destinationId, String dateOfJourney, Int16 seatCount, String seatType, String URL, String ConsumerKey, string providername) { //Convert dd-mm-yyyy format to API compatible format yyyy-mm-dd dateOfJourney = dateOfJourney.Split('-')[2] + "-" + dateOfJourney.Split('-')[1] + "-" + dateOfJourney.Split('-')[0]; try { requestBody = "<?xml version='1.0'?><methodCall>" + "<methodName>select.bustojurney</methodName>" + "<params><param><value><struct>" + "<member><name>jdate</name><value><string>" + dateOfJourney + "</string></value></member>" + "<member><name>sourceid</name><value><string>" + sourceId + "</string></value></member>" + "<member><name>destinationid</name><value><string>" + destinationId + "</string></value></member>" + "<member><name>psgr_count</name><value><string>" + seatCount + "</string></value></member>" + "<member><name>seat_sleeper</name><value><string>" + seatType + "</string></value></member>" + "</struct></value></param></params></methodCall>"; xmlNodes = getXmlNodeList(requestBody, URL, ConsumerKey); AvailableTrips objAvailableTrips = new AvailableTrips(); if (xmlNodes != null) { foreach (XmlNode xNode in xmlNodes) { LJ.CLB.DTO.TripDetails objTripDetails = new DTO.TripDetails(); objTripDetails.providerName = providername; objTripDetails.boardingTimes = null;//String.Empty; objTripDetails.cancellationPolicy = String.Empty; objTripDetails.droppingTimes = null;//String.Empty; objTripDetails.sourceId = int.Parse(sourceId.ToString()); objTripDetails.destinationId = int.Parse(destinationId.ToString()); objTripDetails.partialCancellationAllowed = "false"; XmlNodeList nodeNameList = xNode.SelectNodes("member/name"); XmlNodeList nodeValueList = xNode.SelectNodes("member/value"); for (int i = 0; i < nodeNameList.Count; i++) { switch (nodeNameList.Item(i).InnerText.ToLower()) { case "service_id": objTripDetails.id = nodeValueList.Item(i).InnerText; break; case "traveler_agent": if (nodeValueList.Item(i).InnerText == "") { objTripDetails.travels = "Kallada Tours & Travels"; } else { objTripDetails.travels = nodeValueList.Item(i).InnerText; } break; case "departure_time": objTripDetails.departureTime = nodeValueList.Item(i).InnerText; break; case "arrival_time": objTripDetails.arrivalTime = nodeValueList.Item(i).InnerText; break; case "seat_fare_with_taxes": case "seat_fare": objTripDetails.fares = nodeValueList.Item(i).InnerText; break; case "totalavailableseats": objTripDetails.availableSeats = nodeValueList.Item(i).InnerText; break; case "remaining_seats": objTripDetails.availableSeats = nodeValueList.Item(i).InnerText; break; case "service_type": objTripDetails.busType = nodeValueList.Item(i).InnerText; break; case "boardingpoints": #region Boarding Points string strBP = ""; XmlDocument xmlDocBP = new XmlDocument(); xmlDocBP.LoadXml(nodeValueList.Item(i).InnerXml); XmlNodeList nodesBP = xmlDocBP.GetElementsByTagName("array"); foreach (XmlNode item in nodesBP) { foreach (XmlNode item1 in item.SelectNodes("data/value")) { strBP = (strBP == "") ? item1.InnerText : strBP + "%&&&%" + item1.InnerText; } } //objTripDetails.boardingTimes = strBP; objTripDetails.boardingTimes = Points(strBP, objTripDetails.travels); #endregion break; case "droppingpoints": #region Dropping Points string strDP = "";//nodeValueList.Item(i).InnerXml; XmlDocument xmlDocDP = new XmlDocument(); xmlDocDP.LoadXml(nodeValueList.Item(i).InnerXml); XmlNodeList nodesDP = xmlDocDP.GetElementsByTagName("array"); foreach (XmlNode item in nodesDP) { foreach (XmlNode item1 in item.SelectNodes("data/value")) { strDP = (strDP == "") ? item1.InnerText : strDP + ";" + item1.InnerText; } } objTripDetails.droppingTimes = Points(strDP, objTripDetails.travels); #endregion break; default: break; } } objTripDetails.duration = Duration(objTripDetails.departureTime, objTripDetails.arrivalTime); objAvailableTrips.Add(objTripDetails); } } return objAvailableTrips; } catch (Exception ex) { throw ex; } }