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))); }
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); } } }
static void Main(string[] args) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var tflApi = new TflApi(); var postcodeApi = new PostcodeApi(); CliInterface.RunUserCommandLoop(tflApi, postcodeApi); }
private static string GetPredictionsForPostcode(TflApi tflApi, PostcodeApi postcodeApi, string postcode) { var postcodeData = postcodeApi.GetPostcodeData(postcode); return(GetPredictionsForLatLon(tflApi, postcodeData.latitude, postcodeData.longitude)); }