public IHttpActionResult Get(string countryName) { var cities = _weatherService.GetCities(countryName); if (cities == null || cities.Count() == 0) { return(NotFound()); } return(Ok(_weatherService.GetCities(countryName))); }
public HttpResponseMessage Get(string country) { if (string.IsNullOrEmpty(country) || string.IsNullOrWhiteSpace(country)) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new BaseApiResponse { Code = InternalApiStatusCode.FailedRequestValidation, Message = "country is invalid" })); } var countryResposne = new CountryCityResponse(); try { var result = _weatherService.GetCities(country); if (!result.IsSuccess) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, new BaseApiResponse { Code = InternalApiStatusCode.Error, Message = "Failed to fetch cities" })); } countryResposne.Cities = result.Cities; countryResposne.Code = InternalApiStatusCode.Success; countryResposne.Message = "list of cities retrieved"; return(Request.CreateResponse(HttpStatusCode.OK, countryResposne)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }
public IActionResult GetCityNames() { try { var getCityList = _weatherService.GetCities(); if (getCityList != null && getCityList.Count() > 0) { return(Ok(getCityList)); } return(StatusCode(StatusCodes.Status400BadRequest, Constants.NoResultsFound)); } catch (Exception) { return(StatusCode(500, "Something went wrong")); } }
private async Task GetSearchData(string value) { try { var data = await dataService.GetCities(value); if (CityList != null) { CityList.Clear(); } foreach (var item in data) { CityList.Add(item); } } catch (Exception ex) { //await dialogService.ShowMessage(ex.Message, "Notice"); } }
private async void getCities_Click(object sender, RoutedEventArgs e) { var options = await _weatherService.GetCities(this.country.Text); if (null == options) { SetError($"No cities found for '{this.country.Text}'"); } else { SetSuccess($"Please select one of {options.Count()} place(s) in {this.country.Text}."); this.cities.Items.Clear(); this.cities.Items.Add(new KeyValuePair <LocationInfo, string>(null, "Please select...")); foreach (var opt in options) { this.cities.Items.Add(new KeyValuePair <LocationInfo, string>(opt, opt.ToString())); } this.cities.IsEnabled = true; } }
public IHttpActionResult Cities(string country) { try { if (string.IsNullOrEmpty(country)) { return(BadRequest()); } var response = _weatherService.GetCities(country); if (response == null) { return(NotFound()); } return(Ok(response)); } catch (Exception ex) { return(InternalServerError()); } }