/// <summary> /// Read console input and act like a client calling a city search service /// </summary> public void ReadInput() { var blnContinue = true; while (blnContinue) { if (Input.Trim() == string.Empty) { Console.WriteLine($"Please enter a string to search, press Ctrl+{_exit} to exit. Press enter to complete string"); } var key = Console.ReadKey(); Console.Write(Environment.NewLine); if (key.Modifiers == ConsoleModifiers.Control && key.Key == ConsoleKey.X) { Console.WriteLine("Exit sequence entered, exiting"); blnContinue = false; } else if (key.Key == ConsoleKey.Enter) { //We have finished with the current typeahead search, starting a new one Input = string.Empty; } else { //Validate input, not supporting special characters other than space and dash if (ValidateInput(Char.ToLower(key.KeyChar))) { Input += key.KeyChar; //Do matches var matches = _cityFinder.Search(Input.ToLower()); //Output some information Console.WriteLine($"Found {matches.NextCities.Count} matches"); Console.WriteLine($"Cities:{string.Join(",", matches.NextCities.Select(c => c))}"); Console.WriteLine($"Next Letters:{string.Join(",", matches.NextLetters.Select(c => c))}"); //Add an empty line to make this easier to read Console.WriteLine(""); } else { Console.WriteLine("Invalid character"); } } Console.Write($"{Input}"); } }
public IActionResult CitySearch(string city) { // Validate searchString if (city.Length <= 1) { return(this.BadRequest()); } var result = cityFinderService.Search(city); // Validate that the NextCities exists if (!result.NextCities.Any()) { return(this.NotFound()); } return(Ok(result)); }