From ca6b7d311c0f3b4f549b513c9916431955e0dde0 Mon Sep 17 00:00:00 2001 From: usuario Date: Wed, 30 Jul 2025 17:39:28 +0000 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20ajuste=20de=20header=20de=20p=C3=A1g?= =?UTF-8?q?ina?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Pages/Index.cshtml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Pages/Index.cshtml b/Pages/Index.cshtml index 729a85c..52a974c 100644 --- a/Pages/Index.cshtml +++ b/Pages/Index.cshtml @@ -3,8 +3,9 @@ @{ ViewData["Title"] = "Clientes"; } +
-

Clientes

+

Clientes

-- 2.49.1 From eb6f56021315da45443e7f3c0844d86a4b13e87d Mon Sep 17 00:00:00 2001 From: usuario Date: Wed, 30 Jul 2025 18:02:15 +0000 Subject: [PATCH 2/3] add: Listagem de clientes --- Data/SqliteClientRepository.cs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Data/SqliteClientRepository.cs b/Data/SqliteClientRepository.cs index 2aab76a..6cd12b3 100644 --- a/Data/SqliteClientRepository.cs +++ b/Data/SqliteClientRepository.cs @@ -20,8 +20,32 @@ namespace Workshop8.Data public async Task> GetAllClientsAsync() { - // TODO: implementar SELECT - return new List(); + var clientes = new List(); + + await using (var connection = new SqliteConnection(_connectionString)) + { + await connection.OpenAsync(); + await using (var cmd = connection.CreateCommand()) + { + 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 clientes; } public async Task AddClientAsync(Cliente c) -- 2.49.1 From 68ccae9eb3fed38ecb8399ad919a83338d6f07e3 Mon Sep 17 00:00:00 2001 From: usuario Date: Wed, 30 Jul 2025 18:25:27 +0000 Subject: [PATCH 3/3] add: edicao de clientes --- Data/SqliteClientRepository.cs | 51 ++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/Data/SqliteClientRepository.cs b/Data/SqliteClientRepository.cs index 6cd12b3..37dfd03 100644 --- a/Data/SqliteClientRepository.cs +++ b/Data/SqliteClientRepository.cs @@ -36,31 +36,70 @@ namespace Workshop8.Data { clientes.Add(new Cliente { - Id = reader.GetInt32(0), - Nome = reader.GetString(1), - Email = reader.GetString(2), + Id = reader.GetInt32(0), + Nome = reader.GetString(1), + Email = reader.GetString(2), CriadoEm = reader.GetDateTime(3) }); } } } + connection.Close(); + connection.Dispose(); } return clientes; } 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) { - // 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) { - // 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(); + } + } } } } -- 2.49.1