async Task RefreshCommandExecute() { try { await Task.FromResult <object>(null); if (IsBusy) { return; } IsBusy = true; RefreshCommand.ChangeCanExecute(); Ceps.Clear(); foreach (var item in DatabaseService.Current.CepGetAll()) { Ceps.Add(item); } } catch (Exception ex) { throw; } }
public CepsViewModel() : base() { MessagingCenter.Subscribe <BuscaCepViewModel>(this, "ADICIONAR_CEP", (sender) => { if (!Ceps.Any(lbda => lbda.Equals(sender.CEP))) { Ceps.Add(sender.CEP); } }); }
async Task RefreshCommandExecute() { try { if (IsBusy) { return; } IsBusy = true; RefreshCommand.ChangeCanExecute(); Ceps.Clear(); // Recupera informações do banco de dados remoto API (Aula 4) foreach (var item in await BuscaCepHttpClient.Current.GetCeps()) { Ceps.Add(item); } // Recupera informações do banco de dados local (SQLite - Aula 3 parte 2) //foreach (var item in DatabaseService.Current.CepGetAll()) //{ // Ceps.Add(item); //} } catch (UnauthorizedAccessException ex) { if (await App.Current.MainPage.DisplayAlert("Ooops", ex.Message, "Sim", "Não")) { await BuscaCepHttpClient.Current.Autenticar(SEU_USUARIO, SUA_SENHA); IsBusy = false; RefreshCommand.ChangeCanExecute(); await RefreshCommandExecute(); } } catch (InvalidOperationException ex) { await App.Current.MainPage.DisplayAlert("Ooops", ex.Message, "Ok"); } catch (Exception ex) { await App.Current.MainPage.DisplayAlert("Ah não!", ex.Message, "Ok"); } finally { IsBusy = false; RefreshCommand.ChangeCanExecute(); } }
private async Task RefreshCommandExecute() { try { await Task.FromResult <object>(null); RefreshCommand.ChangeCanExecute(); //LIMPAMOS A LISTA ANTES DE APRESENTAR AO NOSSO CLIENTE Ceps.Clear(); //ADICIONA O NOVO CEP A LISTA QUE VAI PARA A VIEW foreach (var item in DatabaseService.Current.GetAll()) { Ceps.Add(item); } } catch (Exception) { throw; } }