Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Commit

Permalink
Consulta
Browse files Browse the repository at this point in the history
Aceitando cep formatado na consulta.
  • Loading branch information
CristianoRC committed Oct 28, 2016
1 parent 7af26c6 commit cfdd52d
Showing 1 changed file with 57 additions and 69 deletions.
126 changes: 57 additions & 69 deletions DotCep/DotCep/Consultas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,82 +4,70 @@

namespace DotCEP
{
public static class Consultas
{
/// <summary>
/// Retorna um objeto do tipo Enereco com todas as informações do CEP informado.
/// </summary>
/// <returns>The endereco completo.</returns>
/// <param name="CEP">CE.</param>
public static Endereco ObterEnderecoCompleto(string CEP)
{
Endereco enderecoBase = new Endereco();
public static class Consultas
{
public static Endereco ObterEnderecoCompleto(string CEP)
{
Endereco enderecoBase = new Endereco();

if (CEP.ToString().Length == 8)
{
String StrJSON = ControleRequisicoes.ObterStringJSONS(ControleDeUrl.GerarURLDaPesquisa(CEP));

enderecoBase = JsonConvert.DeserializeObject<Endereco>(StrJSON);
}
if (Validacoes.VerificarValidadeDoCep(CEP))
{
if (CEP.Length == 9)
{
CEP = CEP.Replace("-", "");
}

return enderecoBase;
}
String StrJSON = ControleRequisicoes.ObterStringJSONS(ControleDeUrl.GerarURLDaPesquisa(CEP));

/// <summary>
/// Possíveis enderecos, utilizando o filtro de estado, cidade e logradouro,
/// </summary>
/// <returns>The lista de possiveis enderecos.</returns>
/// <param name="UF">UF.</param>
/// <param name="Cidade">Cidade.</param>
/// <param name="logradouro">Logradouro.</param>
public static List<Endereco> ObterListaDeEnderecos(UF UF, String Cidade, String Logradouro)
{
List<Endereco> Enderecos = new List<Endereco>();
String url = ControleDeUrl.GerarURLDaPesquisa(UF, Cidade, Logradouro);
String StrJSON = ControleRequisicoes.ObterStringJSONS(url);
enderecoBase = JsonConvert.DeserializeObject<Endereco>(StrJSON);
}

Enderecos = JsonConvert.DeserializeObject<List<Endereco>>(StrJSON);
return enderecoBase;
}

return Enderecos;
}

/// <summary>
/// Obtem um CEP, mas só se as informações forem unicos e verdadeiros, se não ele retorna valores Empty.
/// </summary>
/// <returns>The CEP.</returns>
/// <param name="UF">UF.</param>
/// <param name="Cidade">Cidade.</param>
/// <param name="Logradouro">Logradouro.</param>
/// <param name="Formatado">If set to <c>true</c> formatado.</param>
public static string ObterCEP(UF UF, String Cidade, String Logradouro, bool Formatado)
{
string saida = string.Empty;
List<Endereco> ListaDeEnderecos = ObterListaDeEnderecos(UF, Cidade, Logradouro);
public static List<Endereco> ObterListaDeEnderecos(UF UF, String Cidade, String Logradouro)
{
List<Endereco> Enderecos = new List<Endereco>();
String url = ControleDeUrl.GerarURLDaPesquisa(UF, Cidade, Logradouro);
String StrJSON = ControleRequisicoes.ObterStringJSONS(url);

if (ListaDeEnderecos.Count == 1)
{
if (Formatado)
{
saida = ListaDeEnderecos[0].cep;
}
else
{
saida = ListaDeEnderecos[0].cep.Replace("-", "");
}
}
else
{
if (Formatado)
{
saida = " - ";
}
else
{
saida = String.Empty;
}
}
Enderecos = JsonConvert.DeserializeObject<List<Endereco>>(StrJSON);

return saida;
}
}
return Enderecos;
}


public static string ObterCEP(UF UF, String Cidade, String Logradouro, bool Formatado)
{
string saida = string.Empty;
List<Endereco> ListaDeEnderecos = ObterListaDeEnderecos(UF, Cidade, Logradouro);

if (ListaDeEnderecos.Count == 1)
{
if (Formatado)
{
saida = ListaDeEnderecos[0].cep;
}
else
{
saida = ListaDeEnderecos[0].cep.Replace("-", "");
}
}
else
{
if (Formatado)
{
saida = " - ";
}
else
{
saida = String.Empty;
}
}

return saida;
}
}
}

0 comments on commit cfdd52d

Please sign in to comment.