Retail_manager/RMDataManagerLibrary/Internal/DataAccess/SqlDataAccess.cs
s459315 aa98988db1 Added RMDataManageLibrary project
Added a way to communicate with database
2022-07-14 19:41:50 +02:00

45 lines
1.4 KiB
C#

using Dapper;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RMDataManagerLibrary.Internal.DataAccess
{
public class SqlDataAccess
{
public string GetConnectionString(string name)
{
return ConfigurationManager.ConnectionStrings[name].ConnectionString;
}
public List<T> LoadData<T, U>(string storedProcedure, U parameters, string connectionStringName)
{
string connectionString = GetConnectionString(connectionStringName);
using (IDbConnection connection = new SqlConnection(connectionString))
{
List<T> rows = connection.Query<T>(storedProcedure, parameters,
commandType: CommandType.StoredProcedure).ToList();
return rows;
}
}
public void SaveData<T>(string storedProcedure, T parameters, string connectionStringName)
{
string connectionString = GetConnectionString(connectionStringName);
using (IDbConnection connection = new SqlConnection(connectionString))
{
connection.Execute(storedProcedure, parameters,
commandType: CommandType.StoredProcedure);
}
}
}
}