Exemple #1
0
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            // Add some properties to the BusInfo view model with the data you want to render on the page.
            // Write code here to populate the view model with info from the APIs.
            // Then modify the view (in Views/Home/BusInfo.cshtml) to render upcoming buses.

            var info = new BusInfo(selection.Postcode);

            if (info.PostCode != null)
            {
                apiManager.GetLonAndLatByPostCode(info.PostCode);
                info.orderedResult  = apiManager.orderedResult;
                info.orderedResult2 = apiManager.orderedResult2;
                info.BusStopName1   = apiManager.busStopName + " " + apiManager.stopLetter1;
                info.BusStopName2   = apiManager.bustStopName2 + " " + apiManager.stopLetter2;
                info.isInLondon     = apiManager.inLondon;
            }
            else
            {
                info.isInLondon = apiManager.inLondon;
            }



            return(View(info));
        }
Exemple #2
0
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            // Add some properties to the BusInfo view model with the data you want to render on the page.
            // Write code here to populate the view model with info from the APIs.
            // Then modify the view (in Views/Home/BusInfo.cshtml) to render upcoming buses.
            var postcode = new BusInfo(selection.Postcode);

            try
            {
                var coordinates = ApiFetcher.GetCoordinates(postcode.PostCode);

                var stopPoints = ApiFetcher.GetStopPoints(coordinates.result);

                var busStops = new List <BusStop>();

                foreach (var stopPoint in stopPoints)
                {
                    var buses = ApiFetcher.GetBuses(stopPoint);
                    foreach (var bus in buses)
                    {
                        bus.timeToStation = bus.timeToStation / 60;
                    }
                    var busStop = new BusStop(buses, stopPoint.commonName);

                    busStops.Add(busStop);
                }

                return(View(busStops));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult ChooseStop(PostcodeSelection selection)
        {
            PostcodeSelection error;
            ValidatePostCode  validatePostCode = new ValidatePostCode(selection);

            if (validatePostCode.valid)
            {
                int i = 0;
                if (selection.MaxDistance == null)
                {
                    selection.MaxDistance = "200";
                }
                if (int.TryParse(selection.MaxDistance, out i))
                {
                    ChooseStop stop = new ChooseStop(selection);
                    return(View(stop));
                }
                error = new PostcodeSelection {
                    Error = "Invalid max distance."
                };
                return(View("Index", error));
            }
            error = new PostcodeSelection {
                Error = "Invalid post code"
            };
            return(View("Index", error));
        }
Exemple #4
0
        public ActionResult BusTimes(PostcodeSelection selection)
        {
            var apiOutput = ApiClass.MakeApiCalls(selection.Postcode);
            var info      = new BusInfo(selection.Postcode, apiOutput);

            return(PartialView(info));
        }
Exemple #5
0
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            // Add some properties to the BusInfo view model with the data you want to render on the page.
            // Write code here to populate the view model with info from the APIs.
            // Then modify the view (in Views/Home/BusInfo.cshtml) to render upcoming buses

            // Validate submitted postcode
            PostcodeAPI pc        = new PostcodeAPI();
            bool        isPcValid = pc.ValidPostcode(selection.Postcode);

            // populate info object to be passed to view
            var info = new Web.ViewModels.BusInfo()
            {
                PostCode = (selection.Postcode == null) ? "" : selection.Postcode.ToUpper(),

                IsPostcodeValid = isPcValid,

                NumberOfStops = (selection.NumberOfStops == null) ? "All" : selection.NumberOfStops,
            };

            // Get arrival info by submitted postcode, only if postcode is valid
            if (isPcValid)
            {
                info.Stops = (selection.NumberOfStops == null) ?
                             Api.BusStop.GetBusStopArrivalsByPostcode(selection.Postcode) :
                             Api.BusStop.GetBusStopArrivalsByPostcode(selection.Postcode, Convert.ToInt32(selection.NumberOfStops));
            }

            return(View(info));
        }
Exemple #6
0
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            // Add some properties to the BusInfo view model with the data you want to render on the page.
            // Write code here to populate the view model with info from the APIs.
            // Then modify the view (in Views/Home/BusInfo.cshtml) to render upcoming buses.
            var info = new BusInfo(selection.Postcode);

            return(View(info));
        }
Exemple #7
0
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            if (selection.Postcode == null)
            {
                selection.Postcode = "";
            }
            var apiOutput = ApiClass.MakeApiCalls(selection.Postcode);
            var info      = new BusInfo(selection.Postcode, apiOutput);

            return(View(info));
        }
Exemple #8
0
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            // Add some properties to the BusInfo view model with the data you want to render on the page.
            // Write code here to populate the view model with info from the APIs.
            // Then modify the view (in Views/Home/BusInfo.cshtml) to render upcoming buses.
            var webpageTables = new List <WebpageTable>();

            List <BusStationData> busStationData;

            try
            {
                busStationData = APIFun.GetBusStationDataFromPostcode(selection.Postcode, 2);
            }
            catch (BadPostcodeException except)
            {
                return(RedirectToAction("Index", new { errorMessage = $"That postcode ({selection.Postcode}) is not valid. Please enter another." }));
            }

            foreach (var busStation in busStationData)
            {
                var newWebpageTable = new WebpageTable();
                newWebpageTable.data  = new List <WebpageTableLine>();
                newWebpageTable.title = busStation.commonName;
                var busData = APIFun.GetSoonestBusesForNaptanID(busStation.naptanId, 5);
                foreach (var bus in busData)
                {
                    var newWebpageTableLine = new WebpageTableLine();
                    newWebpageTableLine.lineName        = bus.lineName;
                    newWebpageTableLine.destinationName = bus.destinationName;
                    var time = bus.timeToStation / 60;
                    if (time == 0)
                    {
                        newWebpageTableLine.arrivalMessage = "Due";
                    }
                    else if (time == 1)
                    {
                        newWebpageTableLine.arrivalMessage = "1 min";
                    }
                    else
                    {
                        newWebpageTableLine.arrivalMessage = $"{time} mins";
                    }
                    newWebpageTable.data.Add(newWebpageTableLine);
                }
                webpageTables.Add(newWebpageTable);
            }

            var info = new BusInfo(selection.Postcode)
            {
                TableData = webpageTables
            };

            return(View(info));
        }
Exemple #9
0
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            var coordinate = postcodeApiHelper.GetPostcodeCoordinates(selection.Postcode);
            var stopPoints = tflApiHelper.GetStopPoints(coordinate);
            var stops      = stopPoints
                             .Take(2)
                             .Select(stop => tflApiHelper.GetTopFiveBuses(stop.naptanId));
            var info = new BusInfo(stops);

            return(View(info));
        }
Exemple #10
0
 public ActionResult BusInfo(PostcodeSelection selection)
 {
     try
     {
         var info = new BusInfo(selection.Postcode);
         return(View(info));
     }
     catch
     {
         return(View("Error"));
     }
 }
Exemple #11
0
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            // Add some properties to the BusInfo view model with the data you want to render on the page.
            // Write code here to populate the view model with info from the APIs.
            // Then modify the view (in Views/Home/BusInfo.cshtml) to render upcoming buses.

            string pc = selection.Postcode;

            BusArrivals           busarr = new BusArrivals();
            List <BusArrivalInfo> bainfo = busarr.GetBusArrivalsByPostcode(pc, 1);

            return(View(bainfo));
        }
Exemple #12
0
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            // Add some properties to the BusInfo view model with the data you want to render on the page.
            // Write code here to populate the view model with info from the APIs.
            // Then modify the view (in Views/Home/BusInfo.cshtml) to render upcoming buses.

            var busArrivals = new Program().CheckPostcodeRegEx(selection.Postcode);

            if (busArrivals == null)
            {
                return(View("Error"));
            }
            var info = new BusInfoDisplay(busArrivals);

            return(View(info));
        }
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            // Add some properties to the BusInfo view model with the data you want to render on the page.
            // Write code here to populate the view model with info from the APIs.
            // Then modify the view (in Views/Home/BusInfo.cshtml) to render upcoming buses.
            var latlong = dataMapper.GetLatLon(selection.Postcode);

            if (latlong.result != null)
            {
                var info = new BusInfo(selection.Postcode);
                return(View(info));
            }
            else
            {
                return(View("error"));
            }
        }
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            // Add some properties to the BusInfo view model with the data you want to render on the page.
            // Write code here to populate the view model with info from the APIs.
            // Then modify the view (in Views/Home/BusInfo.cshtml) to render upcoming buses.
            BusInfo info;

            if (selection.Postcode != null)
            {
                info = new BusInfo(selection.Postcode);
            }
            else
            {
                info = new BusInfo(selection.Location);
            }
            info.UpdateBusStopsFromApi();
            return(View(info));
        }
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            var info = new BusInfo(selection.Postcode);
            List <StopPoint> stopPointList = APIClass.GetAPIData(selection.Postcode);

            var BusStop1 = stopPointList[0];
            var BusStop2 = stopPointList[1];

            var sortedArrivals1 = APIClass.GetArrivalsData(BusStop1.naptanId);
            var sortedArrivals2 = APIClass.GetArrivalsData(BusStop2.naptanId);

            info.BusStop1  = BusStop1;
            info.BusStop2  = BusStop2;
            info.Arrivals1 = sortedArrivals1;
            info.Arrivals2 = sortedArrivals2;

            return(View(info));
        }
Exemple #16
0
        public ActionResult TubeView(PostcodeSelection selection)
        {
            string postcode;
            List <ConsoleApp.TubeInfo> tubes;

            try
            {
                postcode = selection.Postcode.Replace(" ", String.Empty).ToUpper();
                tubes    = tubeInfoList(postcode);
            }
            catch (NullReferenceException)
            {
                return(View("Error"));
            }

            var info = new TubeView(postcode, tubes);

            return(View(info));
        }
Exemple #17
0
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            // Add some properties to the BusInfo view model with the data you want to render on the page.
            // Write code here to populate the view model with info from the APIs.
            // Then modify the view (in Views/Home/BusInfo.cshtml) to render upcoming buses.
            string postcode;
            List <ConsoleApp.BusInfo> buses;

            try
            {
                postcode = selection.Postcode.Replace(" ", String.Empty).ToUpper();
                buses    = busInfoList(postcode);
            }
            catch (NullReferenceException)
            {
                return(View("Error"));
            }

            var info = new BusInfo(postcode, buses);

            return(View(info));
        }
Exemple #18
0
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            // Add some properties to the BusInfo view model with the data you want to render on the page.
            // Write code here to populate the view model with info from the APIs.
            // Then modify the view (in Views/Home/BusInfo.cshtml) to render upcoming buses.

            try
            {
                List <BusPrediction> busPredictions = API.GetBusPredictions(selection.Postcode, 2, 8);
                Coordinates          coordinates    = API.GetCoordinates(selection.Postcode);
                List <StopPoint>     stopPoints     = API.GetClosestStopPoints(coordinates, 2);

                var info = new BusInfo(selection.Postcode, busPredictions, stopPoints);

                return(View(info));
            }
            catch (Exception e)
            {
                var info = new BusInfo(selection.Postcode, e.Message);
                return(View(info));
            }
        }
Exemple #19
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));
        }
Exemple #20
0
        public ActionResult BusInfo(PostcodeSelection selection)
        {
            // Add some properties to the BusInfo view model with the data you want to render on the page.
            // Write code here to populate the view model with info from the APIs.
            // Then modify the view (in Views/Home/BusInfo.cshtml) to render upcoming buses.

            var           api         = new api();
            List <string> coordinates = api.Pcode(selection.Postcode);

            if (coordinates[0] == "error")
            {
                RouteValueDictionary err = new RouteValueDictionary();
                bool error = true;
                err.Add("error", error);
                return(RedirectToAction("Index", err));
            }
            else
            {
                List <Stops> Stops = api.Stops(coordinates);

                //display the 5 next buses stopping at the number of stops requested/found
                List <List <Bus> > stopInfo = new List <List <Bus> >();
                for (var i = 0; i < 2; i++)
                {
                    var resultNames = api.Bus(Stops, i)
                                      .OrderBy(b => b.expectedArrival).ThenBy(b => b.expectedArrival).ToList() //order buses in from soonest to arrive to latest to arrive
                                                                                                               //.Select(b => "Expected arrival: " + b.expectedArrival.Hour + ":" + b.expectedArrival.Minute + "\n" + "Line: " + b.lineName + "\n" + "Destination: " + b.destinationName + "\n" + "Towards: " + b.towards + "\n \n")      //transform to an IEnumerable of strings
                                      .Take(5);                                                                //select first 5 buses

                    stopInfo.Add(resultNames.ToList());
                }

                var info = new BusInfo(selection.Postcode, stopInfo);
                return(View(info));
            }
        }
Exemple #21
0
 public ValidatePostCode(PostcodeSelection selection)
 {
     valid = isValidPostCode(selection.Postcode);
 }
        public IActionResult BusInfo(PostcodeSelection selection)
        {
            var info = new BusInfo(selection.Postcode);

            return(View(info));
        }
Exemple #23
0
 public ChooseStop(PostcodeSelection selection)
 {
     StopPoints = GetLocalStops(selection.Postcode, selection.MaxDistance);
     PostCode   = selection.Postcode;
 }
Exemple #24
0
        public IActionResult BusInfo(PostcodeSelection selection)
        {
            var info = new BusInfo(selection.GetNearestStops);

            return(View(info));
        }