add: edicao de clientes
This commit is contained in:
		| @@ -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(); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user