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

Commit

Permalink
Merge pull request #17 from leonardocintra/version-api
Browse files Browse the repository at this point in the history
CRUD Produto
  • Loading branch information
leonardocintra authored Aug 13, 2016
2 parents 85f82e0 + d956dd9 commit fd37f3b
Show file tree
Hide file tree
Showing 22 changed files with 536 additions and 29 deletions.
3 changes: 1 addition & 2 deletions GeradorNF/GeradorNF.DAO/AbstractCrud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ public static async Task<List<E>> GetAll<E>(string entityURL) where E: class
return Newtonsoft.Json.JsonConvert.DeserializeObject<List<E>>(json).ToList();
}
else
return null;
throw new Exception(response.RequestMessage.ToString());
}
}


public static async Task<HttpResponseMessage> Add<E>(E entity, string entityURL) where E : class
{
using (var client = new HttpClient())
Expand Down
54 changes: 54 additions & 0 deletions GeradorNF/GeradorNF.DAO/ClienteDAO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using GeradorNF.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace GeradorNF.DAO
{
public class ClienteDAO
{
/// <summary>
/// GetCliente - Buscar/Listar TODOS os Emitentes
/// </summary>
/// <returns></returns>
public static async Task<Cliente> GetClienteByIdDAO(string nomeUsuario)
{
try
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(UtilDAO.UrlApi());
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

HttpResponseMessage response = await client.GetAsync("cliente/" + nomeUsuario);

if (response.IsSuccessStatusCode)
{
string json = await response.Content.ReadAsStringAsync();
return Newtonsoft.Json.JsonConvert.DeserializeObject<Cliente>(json);
}
else
throw new Exception(response.RequestMessage.ToString());
}
}
catch (JsonException ex)
{
throw new Exception("JsonException - Não foi possivel buscar o cliente. Erro: " + ex.Message);
}
catch (HttpRequestException ex)
{
throw new Exception("HttpRequestException - Não foi possivel buscar o cliente. Erro: " + ex.Message);
}
catch (Exception ex)
{
throw new Exception("Exception - Não foi possivel buscar os Emitentes. Erro: " + ex.Message);
}
}
}
}
1 change: 1 addition & 0 deletions GeradorNF/GeradorNF.DAO/GeradorNF.DAO.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AbstractCrud.cs" />
<Compile Include="ClienteDAO.cs" />
<Compile Include="EmitenteDAO.cs" />
<Compile Include="EnderecoDAO.cs" />
<Compile Include="ProdutoDAO.cs" />
Expand Down
21 changes: 21 additions & 0 deletions GeradorNF/GeradorNF.Model/Cliente.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GeradorNF.Model
{
public class Cliente
{
[JsonProperty("id")]
public int Id { get; set; }

[JsonProperty("nome")]
public string Nome { get; set; }

[JsonProperty("email")]
public string Email { get; set; }
}
}
3 changes: 3 additions & 0 deletions GeradorNF/GeradorNF.Model/Destinatario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@ public class Destinatario

[JsonProperty("data_cadastro")]
public DateTime DataCadastro { get; set; }

[JsonProperty("cliente")]
public string Cliente { get; set; }
}
}
3 changes: 3 additions & 0 deletions GeradorNF/GeradorNF.Model/Emitente.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,8 @@ public class Emitente

[JsonProperty("data_cadastro")]
public DateTime DataCadastro { get; set; }

[JsonProperty("cliente")]
public string Cliente { get; set; }
}
}
1 change: 1 addition & 0 deletions GeradorNF/GeradorNF.Model/GeradorNF.Model.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Cliente.cs" />
<Compile Include="Destinatario.cs" />
<Compile Include="Emitente.cs" />
<Compile Include="Endereco.cs" />
Expand Down
3 changes: 3 additions & 0 deletions GeradorNF/GeradorNF.Model/Produto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@ public class Produto

[JsonProperty("data_cadastro")]
public DateTime DataCadastro { get; set; }

[JsonProperty("cliente")]
public string Cliente { get; set; }
}
}
3 changes: 3 additions & 0 deletions GeradorNF/GeradorNF.Model/Transportador.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@ public class Transportador

[JsonProperty("data_cadastro")]
public DateTime DataCadastro { get; set; }

[JsonProperty("cliente")]
public string Cliente { get; set; }
}
}
10 changes: 10 additions & 0 deletions GeradorNF/GeradorNF.UI/GeradorNF.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
<Compile Include="frmGeradorArquivo.Designer.cs">
<DependentUpon>frmGeradorArquivo.cs</DependentUpon>
</Compile>
<Compile Include="frmLogin.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frmLogin.Designer.cs">
<DependentUpon>frmLogin.cs</DependentUpon>
</Compile>
<Compile Include="frmPrincipal.cs">
<SubType>Form</SubType>
</Compile>
Expand All @@ -86,6 +92,7 @@
<Compile Include="frmTransporador.Designer.cs">
<DependentUpon>frmTransporador.cs</DependentUpon>
</Compile>
<Compile Include="MyGlobals.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilidade.cs" />
Expand All @@ -98,6 +105,9 @@
<EmbeddedResource Include="frmGeradorArquivo.resx">
<DependentUpon>frmGeradorArquivo.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmLogin.resx">
<DependentUpon>frmLogin.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmPrincipal.resx">
<DependentUpon>frmPrincipal.cs</DependentUpon>
</EmbeddedResource>
Expand Down
14 changes: 14 additions & 0 deletions GeradorNF/GeradorNF.UI/MyGlobals.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using GeradorNF.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GeradorNF.UI
{
public static class MyGlobals
{
public static string Cliente = "https://geradornf-prod.herokuapp.com/cliente/1/"; //hardcode - Tirar
}
}
2 changes: 1 addition & 1 deletion GeradorNF/GeradorNF.UI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmPrincipal());
Application.Run(new frmLogin());
}
}
}
7 changes: 4 additions & 3 deletions GeradorNF/GeradorNF.UI/frmEmitente.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions GeradorNF/GeradorNF.UI/frmEmitente.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ private async void SetEmitente(Enuns.TipoCrud tipoCrud)
emitente.Logradouro = txtEndereco.Text;
emitente.NumeroCasa = txtNumero.Text;
emitente.UF = txtEstado.Text;
emitente.Cliente = MyGlobals.Cliente;
#endregion

HttpResponseMessage response = new HttpResponseMessage();
Expand Down Expand Up @@ -329,5 +330,10 @@ private void btnEditar_Click(object sender, EventArgs e)
lblAcao.Text = "editar";
txtNomeRazao.Focus();
}

private void btnFiltro_Click(object sender, EventArgs e)
{

}
}
}
124 changes: 124 additions & 0 deletions GeradorNF/GeradorNF.UI/frmLogin.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fd37f3b

Please sign in to comment.