add: edicao de clientes

This commit is contained in:
2025-07-30 18:25:27 +00:00
parent eb6f560213
commit 68ccae9eb3

View File

@@ -44,23 +44,62 @@ namespace Workshop8.Data
} }
} }
} }
connection.Close();
connection.Dispose();
} }
return clientes; return clientes;
} }
public async Task AddClientAsync(Cliente c) public async Task AddClientAsync(Cliente c)
{ {
// TODO: implementar INSERT await using (var connection = new SqliteConnection(_connectionString))
{
await connection.OpenAsync();
await using (var cmd = connection.CreateCommand())
{
cmd.CommandText = @"
INSERT INTO Clientes (Nome, Email, CriadoEm)
VALUES (@nome, @email, @criado);";
cmd.Parameters.AddWithValue("@nome", c.Nome);
cmd.Parameters.AddWithValue("@email", c.Email);
cmd.Parameters.AddWithValue("@criado", c.CriadoEm);
await cmd.ExecuteNonQueryAsync();
}
}
} }
public async Task UpdateClientAsync(Cliente c) public async Task UpdateClientAsync(Cliente c)
{ {
// TODO: implementar UPDATE await using (var connection = new SqliteConnection(_connectionString))
{
await connection.OpenAsync();
await using (var cmd = connection.CreateCommand())
{
cmd.CommandText = @"
UPDATE Clientes
SET Nome = @nome,
Email = @email
WHERE Id = @id;";
cmd.Parameters.AddWithValue("@nome", c.Nome);
cmd.Parameters.AddWithValue("@email", c.Email);
cmd.Parameters.AddWithValue("@id", c.Id);
await cmd.ExecuteNonQueryAsync();
}
}
} }
public async Task DeleteClientAsync(int id) public async Task DeleteClientAsync(int id)
{ {
// TODO: implementar DELETE await using (var connection = new SqliteConnection(_connectionString))
{
await connection.OpenAsync();
await using (var cmd = connection.CreateCommand())
{
cmd.CommandText = @"DELETE FROM Clientes WHERE Id = @id;";
cmd.Parameters.AddWithValue("@id", id);
await cmd.ExecuteNonQueryAsync();
}
}
} }
} }
} }