Retail_manager/RMDataManagerLibrary/Internal/DataAccess/SqlDataAccess.cs

45 lines
1.4 KiB
C#
Raw Normal View History

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);
}
}
}
}