using Microsoft.Extensions.Configuration;
using System.Data.SqlClient;
using System.Data;
using Dapper;
namespace DataAccess.DbAccess;
///
/// Bietet lesenden und schreibenden Zugriff auf eine Datenbank.
///
public class SqlDataAccess : ISqlDataAccess
{
private readonly IConfiguration _config;
public SqlDataAccess(IConfiguration config)
{
_config = config;
}
public async Task> LoadData(string storedProcedure, TParameter parameters, string connectionId = "Default")
{
using IDbConnection connection = new SqlConnection(_config.GetConnectionString(connectionId));
return await connection.QueryAsync(storedProcedure, parameters, commandType: CommandType.StoredProcedure);
}
public async Task SaveData(string storedProcedure, TParameter parameters, string connectionId = "Default")
{
using IDbConnection connection = new SqlConnection(_config.GetConnectionString(connectionId));
await connection.ExecuteAsync(storedProcedure, parameters, commandType: CommandType.StoredProcedure);
}
}