private async Task Takingcareofbussiness() { //trying to get information online if some error occurs this is caught and taken care of, a message is displayed in this case try { //indicates the activity indicator to start IsBusy = true; var rest = new ManagerRESTService(new RESTService()); var uri = string.Format(Constants.BranchesUrl, AccountsPage.Bankid); await rest.GetwithoutToken <branchlist>(uri).ContinueWith(t => { //Problem occured a message is displayed to the user if (t.IsFaulted) { Device.BeginInvokeOnMainThread(() => { DisplayAlert("Alert", "Something went wrong sorry :(", "OK"); }); } //everything went fine, information should be displayed else { Device.BeginInvokeOnMainThread(() => { List <Branch> data = t.Result.branches; if (data.Count == 0) { Map = new Map(MapSpan.FromCenterAndRadius( new Position(0, 0), Distance.FromMiles(0.5))) { IsShowingUser = true, HeightRequest = 100, WidthRequest = 960, VerticalOptions = LayoutOptions.FillAndExpand }; Map.Pins.Add(new Pin { Position = new Position(32.6672502, -16.9168688), Label = "Nothing over here ", Address = "Top Secret Company " }); Map.MoveToRegion(MapSpan.FromCenterAndRadius( new Position(32.6672502, -16.9168688), Distance.FromMiles(2.0))); Map.Margin = 5; } else { Debug.WriteLine("Latitude {0}--- Longitude{1} ---- name {2}", data[0].location.latitude, data[0].location.longitude, data[0].name); Map = new Map(MapSpan.FromCenterAndRadius( new Position(data[0].location.latitude, data[0].location.longitude), Distance.FromMiles(0.5))) { IsShowingUser = true, HeightRequest = 100, WidthRequest = 960, VerticalOptions = LayoutOptions.FillAndExpand }; Map.MoveToRegion(MapSpan.FromCenterAndRadius( new Position(data[0].location.latitude, data[0].location.longitude), Distance.FromMiles(1.5))); Map.Margin = 5; for (int i = 0; i < data.Count; i++) { Map.Pins.Add(new Pin { Position = new Position(data[i].location.latitude, data[i].location.longitude), Label = "Name: " + data[i].name, Address = "Address: " + data[i].address.line_1 + data[i].address.line_2 + data[i].address.line_3 + ";City: " + data[i].address.city + ";State: " + data[i].address.state }); } } }); } }); //indicates the activity indicator that all the information is loaded and ready IsBusy = false; Content = new StackLayout { Children = { new Label() { Text = "Branches Locations of Bank: " + AccountsPage.Bankid }, Map } }; } catch (Exception err) { IsBusy = false; await DisplayAlert("Alert", "Internet problems cant receive information", "OK"); Debug.WriteLine("Caught error: {0}.", err); } }
private async Task Takingcareofbussiness() { //trying to get information online if some error occurs this is caught and taken care of, a message is displayed in this case try { //indicates the activity indicator to start IsBusy = true; var rest = new ManagerRESTService(new RESTService()); var uri = string.Format(Constants.BankUrl); //getting information from the online location await rest.GetwithoutToken <Banklist>(uri).ContinueWith(t => { //Problem occured a message is displayed to the user if (t.IsFaulted) { Device.BeginInvokeOnMainThread(() => { DisplayAlert("Alert", "Something went wrong sorry :(", "OK"); }); } //everything went fine, information should be displayed else { Device.BeginInvokeOnMainThread(() => { test = t.Result; _listView = new ListView { HasUnevenRows = true, Margin = 10, SeparatorColor = Color.Teal }; _listView.ItemsSource = test.banks; _listView.ItemTemplate = new DataTemplate(typeof(Cells)); }); } }); //indicates the activity indicator that all the information is loaded and ready IsBusy = false; searchBar.TextChanged += (sender, e) => FilterContacts(searchBar.Text); searchBar.SearchButtonPressed += (sender, e) => { FilterContacts(searchBar.Text); }; Content = new StackLayout { BackgroundColor = Color.Teal, Spacing = 10, Children = { new Label { Text = "Contact list go up and down", HorizontalTextAlignment = TextAlignment.Center }, searchBar, _listView } }; } catch (Exception err) { IsBusy = false; await DisplayAlert("Alert", "Cant receive information", "OK"); Debug.WriteLine("Caught error: {0}.", err); } }