async void SearchCity(object sender, EventArgs args) { await City.ScaleTo(0.95, 50, Easing.CubicOut); await City.ScaleTo(1, 50, Easing.CubicIn); CityLoad.IsVisible = true; City.Text = ""; bool state = true; try { // here you fetch Data HttpClient client = new HttpClient(); HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://api.parse.com/1/classes/City?"); message.Headers.Clear(); message.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt"); message.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC"); HttpResponseMessage response = await client.SendAsync(message); string content = await response.Content.ReadAsStringAsync(); DataToListForCity a = JsonConvert.DeserializeObject <DataToListForCity>(content); foreach (var item in a.GetStringList()) { MyCity.Add(item); } } catch (Exception e) { state = false; } if (state == false) { await DisplayAlert("Problem", "No internet connection", "ok"); CityLoad.IsVisible = false; City.Text = "Choose City"; } else { Application.Current.Properties["Hospital"] = "Choose Hospital"; // to reset hospital value if chosen before city. await Navigation.PushAsync(new CitySearch(MyCity)); CityLoad.IsVisible = false; City.Text = "Choose City"; } }
public async void GetCity() { // here you fetch Data bool state = true; HttpClient client = new HttpClient(); HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://api.parse.com/1/classes/City?"); message.Headers.Clear(); message.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt"); message.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC"); try { HttpResponseMessage response = await client.SendAsync(message); string content = await response.Content.ReadAsStringAsync(); DataToListForCity a = JsonConvert.DeserializeObject <DataToListForCity>(content); foreach (var item in a.GetStringList()) { MyCity.Add(item); ListOfCities.Items.Add(item); //Debug.WriteLine(item); } Loading1.IsVisible = false; Loading1.IsEnabled = false; ListOfCities.IsVisible = true; ListOfCities.IsEnabled = true; // listView.ItemsSource = MyList; } catch (Exception e) { state = false; } if (state == false) { await DisplayAlert("Problem", "Issue with connection", "ok"); } }
public async void GetCityWithCondition() { MyCity.Clear(); ListOfCities.Items.Clear(); // here you fetch Data string H = MyHospital[ListOfHospitals.SelectedIndex]; HttpClient client = new HttpClient(); HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://api.parse.com/1/classes/Hospital?" + WebUtility.UrlEncode("where=" + JsonConvert.SerializeObject(new DataParserForHospital() { Hospital = H }))); message.Headers.Clear(); message.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt"); message.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC"); try { HttpResponseMessage response = await client.SendAsync(message); string content = await response.Content.ReadAsStringAsync(); DataToListForCity a = JsonConvert.DeserializeObject <DataToListForCity>(content); foreach (var item in a.GetStringList()) { MyCity.Add(item); ListOfCities.Items.Add(item); } // listView.ItemsSource = MyList; } catch (Exception e1) { } }