Canducci.Zip
3.1.0.1
dotnet add package Canducci.Zip --version 3.1.0.1
NuGet\Install-Package Canducci.Zip -Version 3.1.0.1
<PackageReference Include="Canducci.Zip" Version="3.1.0.1" />
paket add Canducci.Zip --version 3.1.0.1
#r "nuget: Canducci.Zip, 3.1.0.1"
// Install Canducci.Zip as a Cake Addin #addin nuget:?package=Canducci.Zip&version=3.1.0.1 // Install Canducci.Zip as a Cake Tool #tool nuget:?package=Canducci.Zip&version=3.1.0.1
Canducci ZipCode and AddressCode
Instalação do Pacote
PM> Install-Package Canducci.Zip
Utilização
Busca de CEP
Para a busca de dados de um determinado número de CEP instancie a classe ZipCodeLoad
e no seu método Find
ou FindAsync
passe o número e se a resposta estiver satisfatória os dados estão na classe de resultado ZipCodeResult
, exemplo:
IZipCodeLoad zipCodeLoad = new ZipCodeLoad();
ZipCodeResult result0 = zipCodeLoad.Find("01001000");
if (result0) // ou result0.IsValid
{
ZipCodeItem zipCodeItem = result0; //ou zipCodeItem zipCodeItem = result0.Value;
}
A saída da classe ZipCodeItem
é a seguir:
ZipCodeItem.Zip // cep
ZipCodeItem.Address // logradouro
ZipCodeItem.District // bairro
ZipCodeItem.City // localidade
ZipCodeItem.Uf // uf
ZipCodeItem.Ibge // Ibge
ZipCodeItem.Complement // complemento
ZipCodeItem.Gia // gia
ZipCodeItem.Siafi // siafi
ZipCodeItem.Ddd // ddd
ZipCodeItem.Unity // unidade
ZipCodeItem.State // estado
ZipCodeItem.Region // região
Busca de uma lista de CEP
IAddressCodeLoad addressCodeLoad = new AddressCodeLoad();
AddressCode addressCode = AddressCode.Parse(ZipCodeUf.SP, "SÃO PAULO", "AVE");
AddressCodeResult result1 = addressCodeLoad.Find(addressCode);
if (result1) // ou result1.IsValid
{
AddressCodeItem items = result1; // ou AddressCodeItem items = result1.Value;
}
Note que a saída da classe AddressCodeItem
é uma enumeração (List<>
) de ZipCodeItem
, ou seja, List<ZipCodeItem>
.
Lista de Unidade Federativa
Tanto no objeto de instancia das classes AddressCodeLoad
e ZipCodeLoad
existe um método de extensão que retorna um IDictionary<string, string>
que pode ser utilizado em suas telas para padronização da informação, exemplo:
IZipCodeLoad zipCodeLoad = new ZipCodeLoad();
IAddressCodeLoad addressCodeLoad = new AddressCodeLoad();
System.Collections.Generic.IDictionary<string, string> items0_List = zipCodeLoad.UFToList();
System.Collections.Generic.IDictionary<string, string> items1_List = addressCodeLoad.UFToList();
Essas duas variaveis (items0_List
e items1_List
) são da mesma instância e são geradas a partir do Enum
ZipCodeUf
o mesmo para facilitar na criação de suas interfaces
de programação.
Aplicação MVC Core
No exemplo do controller
TestController
tem dois métodos:
[HttpPost]
public async Task<IActionResult> Index([FromBody] ZipCodeData data)
{
if (ModelState.IsValid)
{
if (ZipCode.TryParse(data.Value, out ZipCode zipCode))
{
ZipCodeResult zipCodeResult = await ZipCodeLoad.FindAsync(zipCode);
return Json(zipCodeResult);
}
}
return Json(new { IsValid = false });
}
[HttpPost]
public async Task<IActionResult> Address([FromBody] AddressCodeData data)
{
if (AddressCode.TryParse(ParseZipCodeUf(data.Uf), data.City, data.Address, out AddressCode addressCode))
{
AddressCodeResult addressCodeResult = await AddressCodeLoad.FindAsync(addressCode);
return Json(addressCodeResult);
}
return Json(new { IsValid = false });
}
private ZipCodeUf ParseZipCodeUf(string uf) => Enum.Parse<ZipCodeUf>(uf);
com o código que retornar um json
para Front-End
de como utilizar o pacote Canducci.Zip e nesse link todo o projeto exemplo.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 is compatible. netcoreapp3.1 is compatible. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 is compatible. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.0
- System.Text.Json (>= 4.7.0)
-
.NETCoreApp 3.1
- System.Text.Json (>= 4.7.0)
-
.NETFramework 4.7
- System.Text.Json (>= 4.7.0)
-
.NETFramework 4.8
- System.Text.Json (>= 4.7.0)
-
.NETStandard 2.0
- System.Text.Json (>= 4.7.0)
-
.NETStandard 2.1
- System.Text.Json (>= 4.7.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Canducci.Zip:
Package | Downloads |
---|---|
Canducci.Zip.Mvc.Core
Canducci.Zip.Mvc.Core |
|
Canducci.Zip.Mvc
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.