Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Postcode:");
            string   postcode          = Console.ReadLine();
            var      PostcodeApiClient = new PostcodeApiClient();
            Postcode postcodeData      = PostcodeApiClient.GetLatLong(postcode);

            var         TflApiClient = new TflApiClient();
            List <Stop> busStops     = TflApiClient.GetBusStopCodes(postcodeData);

            int[] zeroOne = new int[] { 0, 1 };
            foreach (int i in zeroOne)
            {
                var nextStop = busStops[i];
                Console.WriteLine(nextStop.commonName);
                var nearestStopCode = nextStop.naptanId;
                PrintBusTimes(TflApiClient.GetBusTimes(nearestStopCode));
            }

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            bool        valid = true;
            List <Stop> stops = new List <Stop>();

            var      PostcodeApiClient = new PostcodeApiClient();
            Postcode postcodeData      = PostcodeApiClient.GetLatLong(selection.Postcode);

            if (postcodeData == null)
            {
                valid = false;
            }
            else
            {
                var TflApiClient = new TflApiClient();
                stops = TflApiClient.GetBusStopCodes(postcodeData);

                if (!stops.Any())
                {
                    valid = false;
                }

                foreach (Stop s in stops)
                {
                    s.buses = TflApiClient.GetBusTimes(s.naptanId);
                }
            }

            var info = new BusInfo(selection.Postcode)
            {
                PostCode = selection.Postcode,
                Stops    = stops,
                Valid    = valid
            };

            return(View(info));
        }