public IHttpActionResult PostSeacrhTrips(TripSearch trip)
        {
            List <Trip> trips = tripRepository.GetAll().Where(t => t.LocationFrom == trip.LocationFrom && t.LocationTo == trip.LocationTo && t.Timing == trip.JourneyDate).ToList();

            //List<Trip> trips = tripRepository.GetAll().ToList();
            return(Ok(trips));
        }
Пример #2
0
        public async Task <TripSearchResult> SearchForTrip(TripSearch search)
        {
            TripSearchResult val = await Task.Factory.StartNew <TripSearchResult>(() =>
            {
                TripSearchResult searchResult = new TripSearchResult();

                var client = new RestClient(URI_STRING);

                client.UserAgent = USER_AGENT;
                var request      = new RestRequest("/api/OTP", Method.GET);

                request.RequestFormat = DataFormat.Json;

                request.AddParameter("startLatitude", search.StartLatitude);
                request.AddParameter("startLongitude", search.StartLongitude);
                request.AddParameter("startLocation", search.StartLocation);
                request.AddParameter("endLatitude", search.EndLatitude);
                request.AddParameter("endLongitude", search.EndLongitude);
                request.AddParameter("endLocation", search.EndLocation);
                request.AddParameter("searchByArriveByTime", search.SearchByArriveByTime);
                request.AddParameter("time", search.Time);
                request.AddParameter("needWheelchairAccess", search.NeedWheelchairAccess);
                request.AddParameter("maxWalkMeters", search.MaxWalkMeters);

                IRestResponse <TripSearchResult> response = client.Execute <TripSearchResult>(request);

                searchResult = response.Data;

                if (searchResult != null)
                {
                    foreach (Itinerary itinerary in searchResult.itineraries)
                    {
                        if (itinerary.legs != null)
                        {
                            foreach (Leg leg in itinerary.legs)
                            {
                                if (leg.legGeometry != null)
                                {
                                    if (leg.legGeometry.points != null)
                                    {
                                        leg.googlePoints = GooglePoints.Decode(leg.legGeometry.points);
                                    }
                                }
                            }
                        }
                    }
                }

                return(searchResult);
            });

            return(val);
        }
Пример #3
0
        public async Task <TripSearchResult> SearchForTrips(string startLocation, string endLocation, double maxWalkMeters, DateTime date, bool isDeparture, String cityString, String stateString)
        {
            TripSearch criteria = new TripSearch();

            criteria.MaxWalkMeters        = maxWalkMeters;
            criteria.NeedWheelchairAccess = false;
            criteria.SearchByArriveByTime = !isDeparture;
            criteria.Time = date;

            criteria = parseLocationString(criteria, startLocation, true, cityString, stateString);
            criteria = parseLocationString(criteria, endLocation, false, cityString, stateString);

            TripSearchResult searchResult = await mTripManager.SearchForTrip(criteria);

            if (searchResult != null)
            {
                searchResult.searchCriteria = criteria;
                searchResult.itineraries.Sort((a, b) => a.startTime.CompareTo(b.startTime));
            }
            return(searchResult);
        }
Пример #4
0
 private bool WithFreePlases(TripSearch info)
 {
     Trip trip = info.GetTrip;
     return ByedPlases(trip) == trip.Train.SeatsCount;
 }
Пример #5
0
        private TripSearch parseLocationString(TripSearch criteria, string searchString, bool isStart, String cityString, String stateString)
        {
            double latitude       = 0;
            double longitude      = 0;
            string locationString = "";

            string latLonRegExPattern = "^(\\-?\\d+(\\.\\d+)?),\\s*(\\-?\\d+(\\.\\d+)?)$";

            Regex r = new Regex(latLonRegExPattern, RegexOptions.IgnoreCase);

            // Match the regular expression pattern against start location.
            Match matches = r.Match(searchString);

            if (matches.Success)
            {
                string[] inputSplitArray = searchString.Split(",".ToCharArray());

                latitude  = Convert.ToDouble(inputSplitArray [0].Trim());
                longitude = Convert.ToDouble(inputSplitArray [1].Trim());
            }
            else
            {
                locationString = searchString;

                string zipRegExPattern = "\\d{5}(-\\d{4})?$";

                r = new Regex(zipRegExPattern, RegexOptions.IgnoreCase);

                // Match the regular expression pattern for zip
                matches = r.Match(searchString);
                bool isLocalized = false;
                isLocalized = matches.Success;

                if (!isLocalized)
                {
                    string stateRegExPattern = "(A[LKSZRAEP]|C[AOT]|D[EC]|F[LM]|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$";
                    r = new Regex(stateRegExPattern, RegexOptions.IgnoreCase);
                    string stringToMatch = searchString.ToUpper();
                    // Match the regular expression pattern for state
                    matches     = r.Match(stringToMatch);
                    isLocalized = matches.Success;

                    if (!isLocalized)
                    {
                        locationString = locationString + " " + cityString + " " + stateString;
                    }
                }
            }

            if (isStart)
            {
                criteria.StartLocation  = locationString;
                criteria.StartLatitude  = latitude;
                criteria.StartLongitude = longitude;
            }
            else
            {
                criteria.EndLocation  = locationString;
                criteria.EndLatitude  = latitude;
                criteria.EndLongitude = longitude;
            }

            return(criteria);
        }