Compare commits
2 Commits
ws8/Vinici
...
ws8/arthur
Author | SHA1 | Date | |
---|---|---|---|
eb6f560213 | |||
ca6b7d311c |
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@@ -21,53 +20,37 @@ namespace Workshop8.Data
|
||||
|
||||
public async Task<IEnumerable<Cliente>> GetAllClientsAsync()
|
||||
{
|
||||
var itens = new List<Cliente>();
|
||||
var clientes = new List<Cliente>();
|
||||
|
||||
using SqliteConnection conn = await GetConnection();
|
||||
|
||||
var cmd = conn.CreateCommand();
|
||||
|
||||
cmd.CommandText = "SELECT Id, Nome, Email, CriadoEm FROM Clientes";
|
||||
|
||||
await using var reader = await cmd.ExecuteReaderAsync();
|
||||
|
||||
while (await reader.ReadAsync())
|
||||
await using (var connection = new SqliteConnection(_connectionString))
|
||||
{
|
||||
var p = new Cliente
|
||||
await connection.OpenAsync();
|
||||
await using (var cmd = connection.CreateCommand())
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
Nome = reader.GetString(1),
|
||||
Email = reader.GetString(2),
|
||||
CriadoEm = reader.GetDateTime(3)
|
||||
};
|
||||
itens.Add(p);
|
||||
cmd.CommandText = @"SELECT Id, Nome, Email, CriadoEm
|
||||
FROM Clientes
|
||||
ORDER BY Id;";
|
||||
await using (var reader = await cmd.ExecuteReaderAsync())
|
||||
{
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
clientes.Add(new Cliente
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
Nome = reader.GetString(1),
|
||||
Email = reader.GetString(2),
|
||||
CriadoEm = reader.GetDateTime(3)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return itens;
|
||||
}
|
||||
|
||||
private static async Task<SqliteConnection> GetConnection()
|
||||
{
|
||||
var conn = new SqliteConnection("Data Source=database.sqlite;");
|
||||
await conn.OpenAsync();
|
||||
return conn;
|
||||
return clientes;
|
||||
}
|
||||
|
||||
public async Task AddClientAsync(Cliente c)
|
||||
{
|
||||
var conn = await GetConnection();
|
||||
|
||||
var cmd = conn.CreateCommand();
|
||||
|
||||
cmd.CommandText = @"INSERT INTO Clientes (nome, email, criadoEm)
|
||||
VALUES (@nome, @email, @criadoEm) ";
|
||||
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.Parameters.Add(new SqliteParameter("@nome", c.Nome));
|
||||
cmd.Parameters.Add(new SqliteParameter("@email", c.Email));
|
||||
cmd.Parameters.Add(new SqliteParameter("@criadoEm", c.CriadoEm));
|
||||
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
|
||||
// TODO: implementar INSERT
|
||||
}
|
||||
|
||||
public async Task UpdateClientAsync(Cliente c)
|
||||
|
@@ -3,8 +3,9 @@
|
||||
@{
|
||||
ViewData["Title"] = "Clientes";
|
||||
}
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center my-3">
|
||||
<h2>Clientes</h2>
|
||||
<h3>Clientes</h3>
|
||||
<button class="btn btn-primary" type="button" id="createClientBtn">Adicionar Cliente</button>
|
||||
</div>
|
||||
<table class="table table-striped">
|
||||
|
BIN
database.sqlite
BIN
database.sqlite
Binary file not shown.
Reference in New Issue
Block a user