using System; using System.Collections.Generic; using BathHouseManagmet.Models; using Microsoft.Extensions.Options; using MySqlConnector; namespace BathHouseManagmet.Database; public class ClientRepository { MySqlConnection connection; public ClientRepository(IOptions connect) { connection = new MySqlConnection(connect.Value.ConnectionString); } public List GetClients() { List result = new(); string sql = "select * from `client`"; try { connection.Open(); using(var command = new MySqlCommand(sql, connection)) using (var reader = command.ExecuteReader()) { while (reader.Read()) { result.Add(new Client { Id = reader.GetInt32("id"), Name = reader.GetString("name"), Surname = reader.GetString("surname"), }); } } connection.Close(); } catch (Exception e) { Console.WriteLine(e); } return result; } }