summaryrefslogtreecommitdiff
path: root/Gestor.Application/Servicos/CepService.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
commit1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch)
treee1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Gestor.Application/Servicos/CepService.cs
parent674ca83ba9243a9e95a7568c797668dab6aee26a (diff)
downloadgestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz
gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip
chore: location
Diffstat (limited to 'Gestor.Application/Servicos/CepService.cs')
-rw-r--r--Gestor.Application/Servicos/CepService.cs161
1 files changed, 0 insertions, 161 deletions
diff --git a/Gestor.Application/Servicos/CepService.cs b/Gestor.Application/Servicos/CepService.cs
deleted file mode 100644
index f33d711..0000000
--- a/Gestor.Application/Servicos/CepService.cs
+++ /dev/null
@@ -1,161 +0,0 @@
-using Agger.Registro;
-using Gestor.Application.Helpers;
-using Gestor.Common.Validation;
-using Gestor.Model.Domain.Generic;
-using Gestor.Model.Helper;
-using Newtonsoft.Json.Linq;
-using System;
-using System.Diagnostics;
-using System.Net;
-using System.Net.Http;
-using System.Net.Http.Headers;
-using System.Runtime.CompilerServices;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Gestor.Application.Servicos
-{
- public class CepService
- {
- private const string GuidGestor = "bbbf4f03-01fc-4300-b430-33e007753578";
-
- public CepService()
- {
- }
-
- private static async Task<string> Authorization()
- {
- string str;
- string empty;
- using (HttpClient httpClient = new HttpClient())
- {
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
- string str1 = DateTime.Now.ToString("yyyy-MM-dd");
- string base64String = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}|{1}|{2}", ApplicationHelper.IdFornecedor, "bbbf4f03-01fc-4300-b430-33e007753578", str1)));
- Uri apiCep = Address.get_ApiCep();
- string[] strArrays = new string[] { "/auth" };
- Uri uri = apiCep.Append(strArrays);
- HttpResponseMessage httpResponseMessage = await httpClient.PostAsync(uri, base64String.ToHttpContent<string>(null, "application/json"));
- if (httpResponseMessage.get_IsSuccessStatusCode())
- {
- JToken item = httpResponseMessage.get_Content().ToJObject().get_Item("token");
- if (item != null)
- {
- empty = item.ToString();
- }
- else
- {
- empty = null;
- }
- }
- else
- {
- empty = string.Empty;
- }
- str = empty;
- }
- return str;
- }
-
- public async Task<EnderecoBase> SearchDirect(string cep)
- {
- return await this.SearchDirectApiAgger(cep);
- }
-
- public async Task<EnderecoBase> SearchDirectApiAgger(string cep)
- {
- EnderecoBase enderecoBase;
- string upper;
- string str;
- string upper1;
- string str1;
- string upper2;
- try
- {
- string str2 = Gestor.Model.Helper.ValidationHelper.OnlyNumber(cep);
- if (!Gestor.Common.Validation.ValidationHelper.IsNullOrEmpty(str2))
- {
- using (HttpClient httpClient = new HttpClient())
- {
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
- string str3 = await CepService.Authorization();
- httpClient.get_DefaultRequestHeaders().TryAddWithoutValidation("Authorization", string.Concat("Bearer ", str3));
- Uri apiCep = Address.get_ApiCep();
- string[] strArrays = new string[] { str2 };
- Uri uri = apiCep.Append(strArrays);
- string str4 = await await httpClient.GetAsync(uri).get_Content().ReadAsStringAsync();
- JObject jObject = JObject.Parse(str4);
- if (jObject == null || str4.Equals("Endereço não encontrado"))
- {
- enderecoBase = null;
- }
- else
- {
- EnderecoBase enderecoBase1 = new EnderecoBase();
- JToken item = jObject.get_Item("logradouro");
- if (item != null)
- {
- upper = item.ToString().ToUpper();
- }
- else
- {
- upper = null;
- }
- enderecoBase1.set_Endereco(upper);
- JToken jToken = jObject.get_Item("bairro");
- if (jToken != null)
- {
- str = jToken.ToString().ToUpper();
- }
- else
- {
- str = null;
- }
- enderecoBase1.set_Bairro(str);
- JToken item1 = jObject.get_Item("cidade");
- if (item1 != null)
- {
- upper1 = item1.ToString().ToUpper();
- }
- else
- {
- upper1 = null;
- }
- enderecoBase1.set_Cidade(upper1);
- JToken jToken1 = jObject.get_Item("estado");
- if (jToken1 != null)
- {
- str1 = jToken1.ToString().ToUpper();
- }
- else
- {
- str1 = null;
- }
- enderecoBase1.set_Estado(str1);
- JToken item2 = jObject.get_Item("cep");
- if (item2 != null)
- {
- upper2 = item2.ToString().ToUpper();
- }
- else
- {
- upper2 = null;
- }
- enderecoBase1.set_Cep(upper2);
- enderecoBase = enderecoBase1;
- }
- }
- }
- else
- {
- enderecoBase = null;
- }
- }
- catch (Exception exception)
- {
- enderecoBase = null;
- }
- return enderecoBase;
- }
- }
-} \ No newline at end of file