Пример #1
0
        public IHttpActionResult PostLog(int journeyId, Log log)
        {
            if (!this.JourneyExists(journeyId))
            {
                return(NotFound());
            }

            log.JourneyId = journeyId;

            // Convert lat and long into a DbGeography-compatible format
            string coordinates = String.Format("POINT({0} {1})", log.Latitude, log.Longitude);

            log.Location = DbGeography.FromText(coordinates);

            // Determine nearest postcode with 3rd party API
            log.Postcode = PostcodeApi.GetPostcodeFromLatLong(Convert.ToDouble(log.Latitude), Convert.ToDouble(log.Longitude));

            ModelState.Clear();
            TryValidateModel(log);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Logs.Add(log);
            db.SaveChanges();

            return(CreatedAtRoute("GetLog", new { journeyId = journeyId, logId = log.Id }, log.GetOutputObject(false)));
        }
Пример #2
0
        public static void RunUserCommandLoop(TflApi tflApi, PostcodeApi postcodeApi)
        {
            while (true)
            {
                Console.WriteLine("\n\"[Postcode]\" to list arrivals at the two closest stops");
                Console.WriteLine("\"Quit\" to quit");

                Console.WriteLine("Please type an option: ");

                var input = Console.ReadLine();

                if (input == "Quit")
                {
                    break;
                }

                try
                {
                    Console.WriteLine(GetPredictionsForPostcode(tflApi, postcodeApi, input));
                }
                catch (Exception ex) when(ex is TflApiException || ex is PostcodeApiException)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            var tflApi      = new TflApi();
            var postcodeApi = new PostcodeApi();

            CliInterface.RunUserCommandLoop(tflApi, postcodeApi);
        }
Пример #4
0
        private static string GetPredictionsForPostcode(TflApi tflApi, PostcodeApi postcodeApi, string postcode)
        {
            var postcodeData = postcodeApi.GetPostcodeData(postcode);

            return(GetPredictionsForLatLon(tflApi, postcodeData.latitude, postcodeData.longitude));
        }