예제 #1
0
        private void BuscarCep(object sender, EventArgs args)
        {
            //TODO - Validações
            string cep = CEP.Text.Trim();

            if (IsValidCEP(cep))
            {
                try
                {
                    Endereco end = ViaCepService.BuscarEnderecoViaCep(cep);

                    if (end != null)
                    {
                        Resultado.Text = string.Format("Endereço: {2}, de {3} {0}, {1}", end.Localidade, end.Uf, end.Logradouro, end.Bairro);
                    }
                    else
                    {
                        DisplayAlert("Erro", "O endereço não foi encontrado para o CEP informado: " + cep, "OK");
                    }
                }
                catch (Exception e)
                {
                    DisplayAlert("Erro crítico", e.Message, "OK");
                }
            }
        }
        private void btnOnclic(object sender, EventArgs args)
        {
            string cep = Cep.Text.Trim();

            if (cepValido(cep))
            {
                try
                {
                    if (cep != null)
                    {
                        Endereco end = ViaCepService.BuscaEnderecoViacep(cep);
                        Resultado.Text = "Rua" + end.logradouro;
                    }
                    else
                    {
                        DisplayAlert("ERRO CRITICO", "Cep Não existe -> " + Cep.Text, "ok");
                    }
                }
                catch (Exception e)
                {
                    DisplayAlert("ERRO CRITICO", e.ToString(), "ok");
                }
            }
            else
            {
            }
        }
예제 #3
0
        private void ButtonSearchCep_Clicked(object sender, EventArgs e)
        {
            //used replace for remvoving the mask char and trim to remove any possible white-spaces
            var cep = entryCep.Text.Replace("-", "").Trim();

            if (isValidCep(cep))
            {
                try
                {
                    address = ViaCepService.searchAddress(cep);
                    if (address.erro == true)
                    {
                        //called entryCep to show masked text
                        textResult.Text =
                            string.Format("Endereço não encontrado para o CEP: {0}", entryCep.Text.Trim());
                    }
                    else
                    {
                        textResult.Text =
                            "Logradouro: " + address.logradouro +
                            "\nBairro: " + address.bairro +
                            "\nCidade: " + address.localidade +
                            "\nUF: " + address.uf;
                    }
                }
                catch (Exception exception)
                {
                    DisplayAlert("ERRO CRÍTICO", exception.Message, "OK");
                }
            }
        }
예제 #4
0
        private void BuscarCEP(object sender, EventArgs args)
        {
            string cep = CEP.Text.Trim();

            if (isValid(cep))
            {
                try {
                    Endereco end = ViaCepService.BuscarEnderecoViaCep(cep);

                    if (end != null)
                    {
                        RESULTADO.Text = "Endereço para o CEP " + cep + ": "
                                         + end.logradouro + ", "
                                         + end.complemento + ", "
                                         + end.bairro + ", "
                                         + end.localidade + ", "
                                         + end.uf + ".";
                    }
                    else
                    {
                        DisplayAlert("Erro", "O endereço não foi encontrado, para o CEP informado: " + cep, "OK");
                    }
                }catch (Exception e)
                {
                    DisplayAlert("Erro", e.Message, "OK");
                }
            }
        }
예제 #5
0
        private void BuscarCep(object sender, EventArgs e)
        {
            string cep = CEP.Text.Trim();

            if (isValidCep(cep))
            {
                try
                {
                    Endereco end = ViaCepService.ConsultaCep(cep);

                    if (end != null)
                    {
                        RESULTADO.Text = String.Format("Rua: {0} \n Bairro: {1} \n Cidade {2} \n UF: {3}", end.Logradouro, end.Bairro, end.Localidade, end.Uf);
                    }
                    else
                    {
                        DisplayAlert("ERRO CRÍTICO", "O endereço não foi encontrado para o CEP informado" + cep, "Fechar");
                    }
                }
                catch (Exception ex)
                {
                    DisplayAlert("ERRO CRÍTICO", ex.Message, "Fechar");
                }
            }
        }
예제 #6
0
        private void BuscarCep(object sender, EventArgs args)
        {
            //Validações
            string cep = txtCep.Text.Trim();

            if (isValidCep(cep))
            {
                try
                {
                    //Lógica do programa
                    EnderecoModel endereco = ViaCepService.BuscarCep(cep);

                    if (endereco != null)
                    {
                        lblLogradouro.Text = $"Endereço: {endereco.Logradouro},{endereco.Bairro}, {endereco.Localidade}, {endereco.Uf}";
                    }
                    else
                    {
                        DisplayAlert("Erro crítico", "Cep não encontrado", "Ok");
                    }
                }
                catch (Exception ex)
                {
                    DisplayAlert("Erro crítico", ex.Message, "Ok");
                }
            }
        }
        private void BuscarCEP(object sender, EventArgs args)
        {
            var cep = Cep.Text.Trim();

            if (CepValido(cep))
            {
                try
                {
                    var endereco = ViaCepService.BuscarEnderecoViaCep(cep);


                    if (endereco != null)
                    {
                        Resultado.Text = $"Endereço: {endereco.Logradouro}, Bairro {endereco.Bairro}, Cidade {endereco.Localidade} - {endereco.Uf},";
                    }
                    else
                    {
                        DisplayAlert("ERRO", $"O endereço não foi encontrado para o CEP informado: {cep}", "OK");
                    }
                }
                catch (Exception e)
                {
                    DisplayAlert("ERRO CRITICO", e.Message, "OK");
                }
            }
        }
예제 #8
0
        private async void BuscarViaCEP(object sender, EventArgs args)
        {
            aparece();
            await Task.Delay(1000);

            if (CEP.Text.Length != 9)
            {
                some();
                await DisplayAlert("ERRO", "CEP Inválido", "OK");
            }
            else
            {
                if (CrossConnectivity.Current.IsConnected)
                {
                    Endereco end = ViaCepService.BuscarEnderecoViaCEP(CEP.Text);
                    Resultado.Text = $"Endereço: {end.Localidade}-{end.Uf} \n" +
                                     (string.IsNullOrWhiteSpace(end.Logradouro) ? "" : $"Rua: {end.Logradouro}\n") +
                                     (string.IsNullOrWhiteSpace(end.Bairro) ? "" : $"Bairro: {end.Bairro}\n");
                }
                else
                {
                    await DisplayAlert("ERRO", "Sem internet, verifique sua conexão e tente novamente", "OK");
                }
            }
            some();
        }
예제 #9
0
        private void BuscarCEP(object sender, TextChangedEventArgs args)
        {
            string cep = cep_entry.Text.Trim();

            if (cep.Length == 9)
            {
                try
                {
                    Endereco end = ViaCepService.BuscarEnderecoViaCep(cep);
                    if (end != null)
                    {
                        resultado.Text = string.Format("Endereço: {0}, {1}, {2}", end.UF, end.Logradouro, end.Bairro);
                    }
                    else
                    {
                        DisplayAlert("ERRO", "O endereço não foi encontrado para o CEP informado: " + cep, "OK");
                    }
                    pais_entry.Text       = "Brasil";
                    uf_entry.Text         = end.UF;
                    logradouro_entry.Text = end.Logradouro;
                    bairro_entry.Text     = end.Bairro;
                }
                catch (Exception e)
                {
                    DisplayAlert("ERRO CRÍTICO", e.Message, "OK");
                }
            }
        }
예제 #10
0
        private void buscarCEP(object sender, EventArgs args)
        {
            string cep = CEP.Text.Trim();

            if (CEPValidator.Validate(cep))
            {
                try {
                    Endereco end = ViaCepService.SearchEndereco(cep);
                    if (end != null)
                    {
                        Result.Text = end.Print();
                    }
                    else
                    {
                        DisplayAlert("Falha",
                                     "Endereço não encontrado!",
                                     "OK");
                    }
                } catch (Exception ex) {
                    System.Console.WriteLine("MainTela: " + ex.Message);
                    DisplayAlert("Serviço indisponível",
                                 "O serviço parece estar com um mal funcionamento.\nTente novamente mais tarde",
                                 "OK");
                }
            }
            else
            {
                DisplayAlert("Falha na consulta!", "CEP inválido! O CEP é composto por 8 números.", "OK");
            }
        }
예제 #11
0
        private void BuscarCep(object sender, EventArgs args)
        {
            var cep = Cep.Text.Trim();

            if (isValidCEP(cep))
            {
                try
                {
                    Endereco endereco = ViaCepService.BuscarEnderecoViaCEP(cep);

                    if (endereco != null)
                    {
                        lbResultado.Text = string.Format("Endereço: {0}, {1}, {2}", endereco.Localidade, endereco.Uf, endereco.Logradouro);
                    }
                    else
                    {
                        DisplayAlert("ERRO", "Endereço não encontrado para o cepe informado: " + cep, "ok");
                    }
                }
                catch (Exception e)
                {
                    DisplayAlert("ERRO", "Erro Crítico", "ok");
                }
            }
        }
        private void BtnBuscarCEP_Clicked(object sender, EventArgs e)
        {
            if ((txtCEP.Text == null) || (txtCEP.Text.Length < 8))
            {
                DisplayAlert("Erro", "CEP Inválido!", "CEP não posso ser vazio ou deve conter no minimo 8 caracteres.", "OK");
                txtCEP.Focus();
            }
            else
            {
                try
                {
                    Endereco endereco = ViaCepService.BuscarEnderecoViaCEP(txtCEP.Text.Trim());


                    if (endereco != null)
                    {
                        txtEndereco.Text = string.Format("Endereço: {0} , {1} , {2}, {3}", endereco.logradouro, endereco.bairro, endereco.localidade, endereco.uf);
                    }
                    else
                    {
                        DisplayAlert("Aviso!", "Endereço não foi encontrado para o cep digitado: " + txtCEP.Text, "OK");
                        txtCEP.Text = "";
                        txtCEP.Focus();
                    }
                }
                catch (Exception ex)
                {
                    DisplayAlert("Erro Crítico", ex.Message, "Ok");
                }
            }
        }
예제 #13
0
        }                                              // utlizando comando para o botao Entrar
        public PesquisaViewModel()
        {
            this.Pesquisa = new Pesquisa();

            PesquisarCommand = new Command(async() =>
            {
                var viaCepService = new ViaCepService();
                try
                {
                    this.Pesquisa = ViaCepService.BuscarEnderecoViaCEP(Pesquisa.Cep);

                    if (Pesquisa.Cep != null)
                    {
                        MessagingCenter.Send(this.Pesquisa, "Pesquisar"); // ENVIA O OBJETO PARA PROXIMA PAGINA
                    }
                }
                catch
                {
                    await Application.Current.MainPage.Navigation.PopAsync();
                }
            }, () =>
            {
                return(!string.IsNullOrEmpty(this.Cep)); // não habilita o botão entrar se o campo n estiver preenchido
            });
        }
예제 #14
0
        private void BuscarCEP(object sender, EventArgs args)
        {
            string cep = CEP.Text.Trim();

            if (isValidaCEP(cep))
            {
                try
                {
                    var end = ViaCepService.BuscaEnderecoViaCep(cep);

                    if (end != null)
                    {
                        Resultado.Text = string.Format("Endereço: {2}, {3} {0}, {1} "
                                                       , end.Localidade, end.UF, end.Logradouro, end.Bairro);
                    }
                    else
                    {
                        DisplayAlert("ERRO", "ENDEREÇO NÃO ENCONTRADO PARA O CEP INFORMADO", "OK");
                    }
                }
                catch (Exception e)
                {
                    DisplayAlert("ERRO CRÍTICO", e.Message, "OK");
                }
            }
        }
예제 #15
0
        private void BuscarCep(object sender, EventArgs args)
        {
            //TODO - Validações.
            string cep = CEP.Text.Trim();

            if (isValidCEP(cep))
            {
                try {
                    Endereco end = ViaCepService.BuscarEnderecoViaCep(cep);

                    if (end != null)
                    {
                        RESULTADO.Text = $"Endereço: {end.Localidade},{end.Uf}, {end.Logradouro}, {end.Bairro} ";
                    }
                    else
                    {
                        DisplayAlert("ERRO", "o endereço não foi encontrado para o CEP Informado: " + end.Cep, "OK");
                    }
                }
                catch (Exception e)
                {
                    DisplayAlert("ERRO CRIticon", e.Message, "OK");
                }
            }
        }
예제 #16
0
        public async Task <int> FindCep()
        {
            var find = CEP.Text.Trim();

            find = find.Replace("-", "");

            if (isValidCep(find))
            {
                try
                {
                    var addressRepositories = await GetAddressBase();

                    Address result = ViaCepService.FindAdressViaCep(find);

                    if (!addressRepositories.Contains((object)result))
                    {
                        var task = await SaveAddressBase(new AddressRepository(result.Cep, result.Logradouro, result.Bairro, result.Logradouro, result.Uf));
                    }


                    RESULT.Text = string.Format(" Endereço:\n {0}\n {1}\n {2}\n {3}\n {4}\n", result.Cep, result.Logradouro, result.Bairro, result.Localidade, result.Uf);
                    return(1);
                }
                catch (Exception e)
                {
                    DisplayAlert("Erro:", e.Message, "OK");
                }
            }

            return(0);
        }
예제 #17
0
        private void BuscarCEP(object sender, EventArgs args)
        {
            //todo logica do programa

            //todo validacoes
            string cep = CEP.Text.Trim();

            if (isValidCep(cep))
            {
                try
                {
                    Endereco end = ViaCepService.BuscarEnderecoViaCep(cep);
                    if (end != null)
                    {
                        RESULTADO.Text = string.Format("Endereço: {0}, {1} {2} {3}  ", end.localidade, end.uf, end.logradouro, end.bairro);
                    }
                    else
                    {
                        DisplayAlert("ERRO", "O Endereço não foi encontrado para o CEP informado" + cep, "OK");
                    }
                }
                catch (Exception e)
                {
                    DisplayAlert("ERRO CRITICO", e.Message, "OK");
                }
            }
        }
예제 #18
0
        private void BuscarCep(object sender, EventArgs e)
        {
            string  cep     = CEP.Text.Trim();
            Address address = ViaCepService.SearchAddressToCep(cep);

            RESULT.Text = String.Format("Endereço: {3}, {0}, {1}, {2}",
                                        address.Localidade, address.Uf, address.Logradouro, address.Bairro);
        }
예제 #19
0
 public void SetUp()
 {
     _viaCepService      = ViaCepService.Default();
     _enderecoRequisicao = new EnderecoRequisicao
     {
         UF         = UF.RS,
         Cidade     = "Porto Alegre",
         Logradouro = "Olavo"
     };
 }
예제 #20
0
        private void adressSearch(object sender, EventArgs args)
        {
            //Logica Botão

            //VAlidações
            string cep = CEP.Text.Trim();
            Adress end = ViaCepService.AdressSearch(cep);

            ADRESS.Text = string.Format("Endereço: {0},{1},{2}", end.localidade, end.uf, end.logradouro);
        }
예제 #21
0
 private void BuscarCep(object sender, EventArgs args)
 {
     if (IsValid(Cep.Text.Trim()))
     {
         Endereco end = ViaCepService.BuscarEnderecoCep(Cep.Text.Trim());
         if (end.logradouro != null)
         {
             Resultado.Text = string.Format("Endereco: {0} \nBairro: {1} \nCidade: {2} - {3}", end.logradouro, end.bairro, end.localidade, end.uf);
         }
         else
         {
             Resultado.Text = "CEP inválido!";
         }
     }
 }
예제 #22
0
        private async void BuscarCep(object sender, EventArgs args)
        {
            try
            {
                string cep = CEP.Text.Trim();

                ValidaCep(cep);

                Endereco end = await ViaCepService.BuscarEnderecoViaCep(cep);

                RESULTADO.Text = $"Cidade: {end.Localidade}   |   Estado: {end.Uf}   |   Logradouro: {end.Logradouro}   |   Bairro: {end.Bairro}";
            }
            catch (Exception ex)
            {
                await DisplayAlert("Atenção", ex.Message, "OK");
            }
        }
        private void BuscaCep()
        {
            try
            {
                Cep cep           = txtBuscaCep.Text;
                var viaCepService = ViaCepService.Default();
                var endereco      = viaCepService.ObterEndereco(cep);

                if (!string.IsNullOrEmpty(endereco.ToString()))
                {
                    txtLogradouro.Text  = endereco.Logradouro;
                    txtBairro.Text      = endereco.Bairro;
                    txtCidade.Text      = endereco.Localidade;
                    txtComplemento.Text = "";
                    txtNumero.Text      = "";
                }
            } catch (Exception e) { MessageBox.Show(e.Message); }
        }
예제 #24
0
        private void BuscarCep(object sender, EventArgs e)
        {
            var cep = txtCep.Text.Trim();

            if (EhCepValido(cep))
            {
                Endereco endereco = ViaCepService.BuscarEnderecoViaCep(cep);

                if (EhEnderecoValido(endereco))
                {
                    lblResultado.Text = $"Endereço: {endereco.Localidade} \n" +
                                        $"UF: {endereco.Uf} \n" +
                                        $"Bairro: {endereco.Bairro} ";
                }
                ;

                txtCep.Text = string.Empty;
            }
        }
예제 #25
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // CORS
            services.AddCors();
            // END CORS

            // BANCO DE DADOS
            services.AddDbContext <DesafioContext>(options => options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
            services.AddScoped <IAuthRepository <User>, AuthRepository>();
            services.AddScoped <IClientRepository <Client>, ClientRepository>();
            // END BANCO DE DADOS

            // FACEBOOK
            services.Configure <Facebook.FaceBookSettings>(Configuration.GetSection("facebook"));
            services.AddSingleton <Facebook.FaceBookHandler>();
            // FIM FACEBOOK

            // TOKEN JWT
            services.AddSingleton <PublicKey>();
            services.AddSingleton <PrivateKey>();
            services.Configure <JwtSettings>(Configuration.GetSection("jwt"));
            services.AddSingleton <IJwtHandler, JwtHandler>();

            var serviceProvider = services.BuildServiceProvider();
            var jwtParameters   = serviceProvider.GetService <IJwtHandler>();

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options =>
            {
                options.TokenValidationParameters = jwtParameters.parameters;
                options.SaveToken            = true;
                options.RequireHttpsMetadata = false;
            });
            // END JWT TOKEN

            // VIACEP
            services.AddSingleton <IViaCepService>(serviceProvier => ViaCepService.Default());
            // END VIACEP
            services.AddControllers().AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);;
        }
예제 #26
0
 /// <inheritdoc />
 public Task RetorneComoJsonAsync(Action <string> callback)
 => callback == null
         ? throw new ArgumentNullException(nameof(callback))
         : Task.Run(async() =>
 {
     try
     {
         using (var viaCepService = ViaCepService.Default())
             callback(await viaCepService.ObterEnderecosComoJsonAsync(_dados));
     }
     catch (Exception e)
     {
         if (_onError == null)
         {
             throw;
         }
         _onError(e);
     }
 });
예제 #27
0
        /// <inheritdoc />
        public void RetorneComoJson(Action <string> callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            try
            {
                using (var viaCepService = ViaCepService.Default())
                    callback(viaCepService.ObterEnderecosComoJson(_dados));
            }
            catch (Exception e)
            {
                if (_onError == null)
                {
                    throw;
                }
                _onError(e);
            }
        }
예제 #28
0
        private async void btnConsultar_ClickedAsync(object sender, EventArgs e)
        {
            actIndLoading.IsRunning = true;
            actIndLoading.IsVisible = true;

            string cep = txtCep.Text.Trim();

            if (isValidCEP(cep))
            {
                try
                {
                    //Endereco end = await ViaCepService.BuscaEndereco(cep);
                    Endereco end = await Task.Run(async() =>
                    {
                        return(await ViaCepService.BuscaEndereco(cep));
                    });

                    if (end != null)
                    {
                        //lblResultado.Text = string.Format("Endereco: {0},{1} - {2} - {3} - {4} - {5}", end.Logradouro, end.Complemento, end.Bairro, end.Localidade, end.Uf, end.Cep);
                        lblResultado.Text = $"Endereço: {end.Logradouro}, {end.Complemento} \nBairro: {end.Bairro} \nCidade: {end.Localidade} \nEstado: {end.Uf} \nCEP: {end.Cep}";
                    }
                    else
                    {
                        await DisplayAlert("ERRO", $"Endereço não encontrado para o CEP informado: {cep}", "OK");
                    }

                    actIndLoading.IsRunning = false;
                    actIndLoading.IsVisible = false;
                }
                catch (Exception exception)
                {
                    await DisplayAlert("ERRO CRÍTICO", exception.Message, "OK");

                    actIndLoading.IsRunning = false;
                    actIndLoading.IsVisible = false;
                    throw;
                }
            }
        }
        public void FindCep(object sender, EventArgs args)
        {
            if (string.IsNullOrEmpty(txtCEP.Text))
            {
                DisplayAlert("Erro", "Campo vazio!", "Ok");
            }
            else
            {
                string cep = txtCEP.Text.Trim();
                cep = cep.Replace("-", "");

                if (IsValidCep(cep))
                {
                    try
                    {
                        Address address = ViaCepService.FindAddressByCep(cep);

                        if (address != null)
                        {
                            lblResult.Text = string.Format("Endereço: {0}, {1} - {2}, {3} - {4}, {5}",
                                                           address.logradouro, address.complemento, address.bairro, address.localidade,
                                                           address.uf, address.cep);
                        }
                        else
                        {
                            DisplayAlert("Erro", "Endereço não encontrado!", "OK");
                        }
                    }
                    catch (Exception e)
                    {
                        DisplayAlert("Erro", e.Message, "OK");
                    }
                }
                else
                {
                    DisplayAlert("Erro", "Cep inválido!", "Ok");
                }
            }
        }
예제 #30
0
        private void BuscarCep(object sender, EventArgs args)
        {
            var cep = txtCep.Text.Trim();

            try
            {
                if (IsValidCep(cep))
                {
                    var resultado = ViaCepService.BuscarEnderecoViaCep(cep);
                    lbResultado.Text = $"Endereço: {resultado.Localidade}, {resultado.Uf}, {resultado.Logradouro}";
                }
                else
                {
                    DisplayAlert("Atenção", "Cép inválido!", "Ok");
                    txtCep.Text = "";
                    txtCep.Focus();
                }
            }
            catch (Exception e)
            {
                DisplayAlert("Erro", "Não foi possível encontrar o cep", "Ok");
            }
        }