48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
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<DatabaseConnection> connect)
|
|
{
|
|
connection = new MySqlConnection(connect.Value.ConnectionString);
|
|
}
|
|
|
|
public List<Client> GetClients()
|
|
{
|
|
List<Client> 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;
|
|
}
|
|
|
|
|
|
} |