51 lines
1.1 KiB
C#
51 lines
1.1 KiB
C#
using System;
|
|
using Microsoft.Extensions.Options;
|
|
using MySqlConnector;
|
|
|
|
namespace AutoService.DB;
|
|
|
|
|
|
public abstract class BaseRepository : IDisposable
|
|
{
|
|
protected MySqlConnection connection;
|
|
|
|
public BaseRepository(IOptions<DataBaseConnection> databaseConnection)
|
|
{
|
|
connection = new MySqlConnection(databaseConnection.Value.ConnectionString);
|
|
}
|
|
public bool OpenConnection()
|
|
{
|
|
try
|
|
{
|
|
connection.Open();
|
|
return true;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
return false;
|
|
}
|
|
|
|
}
|
|
public bool CloseConnection()
|
|
{
|
|
try
|
|
{
|
|
connection.Close();
|
|
return true;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
connection.Dispose();
|
|
}
|
|
|
|
|
|
}
|