using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Data.Sqlite; using Microsoft.Extensions.Configuration; using Workshop8.Models; namespace Workshop8.Data { public class SqliteClientRepository : IClientRepository { private readonly string _connectionString; public SqliteClientRepository(IConfiguration configuration) { var dbConfig = configuration.GetSection("Database"); _connectionString = dbConfig.GetValue("UseRemote") ? dbConfig.GetValue("Remote") : dbConfig.GetValue("Local"); } public async Task> GetAllClientsAsync() { // SELECT var clientes = new List(); await using var conn = new SqliteConnection(_connectionString); await conn.OpenAsync(); var cmd = conn.CreateCommand(); cmd.CommandText = "SELECT id, nome, email, CriadoEm FROM Clientes;"; await using var reader = await cmd.ExecuteReaderAsync(); while (await reader.ReadAsync()) { var c = new Cliente { Id = reader.GetInt32(0), Nome = reader.GetString(1), Email = reader.GetString(2), CriadoEm = reader.GetDateTime(3) }; clientes.Add(c); } return clientes; return new List(); } public async Task AddClientAsync(Cliente c) { // TODO: implementar INSERT } public async Task UpdateClientAsync(Cliente c) { // TODO: implementar UPDATE } public async Task DeleteClientAsync(int id) { // TODO: implementar DELETE } } }