示例#1
0
        async Task RefreshCommandExecute()
        {
            if (this.IsBusy)
            {
                return;
            }

            this.IsBusy = true;
            this.RefreshCommand.ChangeCanExecute();

            try
            {
                Ceps.Clear();

                foreach (var item in Data.DatabaseService.Current.Listar())
                {
                    this.Ceps.Add(item);
                }

                await Task.FromResult(0);
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Alerta!", ex.Message, "OK");
            }
            finally
            {
                this.IsBusy = false;
                this.RefreshCommand.ChangeCanExecute();
            }
        }
示例#2
0
        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;
            }
        }
        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;
            }
        }