public void SetUp() { _viaCepService = ViaCepService.Default(); _enderecoRequisicao = new EnderecoRequisicao { UF = UF.RS, Cidade = "Porto Alegre", Logradouro = "Olavo" }; }
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); } }
// 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);; }
/// <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); } });
/// <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); } }