Add project files.
This commit is contained in:
19
EmployeeLibrary/Data/EmployeeData.cs
Normal file
19
EmployeeLibrary/Data/EmployeeData.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using EmployeeLibrary.Models;
|
||||
|
||||
namespace EmployeeLibrary.Data;
|
||||
|
||||
public class EmployeeData : IEmployeeData
|
||||
{
|
||||
private readonly ISqlDataAccess _db;
|
||||
|
||||
public EmployeeData(ISqlDataAccess db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public async Task<List<EmployeeModel>> GetEmployees()
|
||||
{
|
||||
var output = await _db.LoadDataAsync<EmployeeModel, dynamic>("dbo.spEmployee_GetAll", new { });
|
||||
return output;
|
||||
}
|
||||
}
|
||||
9
EmployeeLibrary/Data/IEmployeeData.cs
Normal file
9
EmployeeLibrary/Data/IEmployeeData.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using EmployeeLibrary.Models;
|
||||
|
||||
namespace EmployeeLibrary.Data
|
||||
{
|
||||
public interface IEmployeeData
|
||||
{
|
||||
Task<List<EmployeeModel>> GetEmployees();
|
||||
}
|
||||
}
|
||||
7
EmployeeLibrary/Data/ISqlDataAccess.cs
Normal file
7
EmployeeLibrary/Data/ISqlDataAccess.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace EmployeeLibrary.Data
|
||||
{
|
||||
public interface ISqlDataAccess
|
||||
{
|
||||
Task<List<T>> LoadDataAsync<T, U>(string sql, U parameters, string connectionStringName = "Default");
|
||||
}
|
||||
}
|
||||
31
EmployeeLibrary/Data/SqlDataAccess.cs
Normal file
31
EmployeeLibrary/Data/SqlDataAccess.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EmployeeLibrary.Data;
|
||||
|
||||
public class SqlDataAccess : ISqlDataAccess
|
||||
{
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public SqlDataAccess(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public async Task<List<T>> LoadDataAsync<T, U>(string sql,
|
||||
U parameters,
|
||||
string connectionStringName = "Default")
|
||||
{
|
||||
|
||||
using IDbConnection connection = new SqlConnection(_config.GetConnectionString(connectionStringName));
|
||||
var rows = await connection.QueryAsync<T>(sql, parameters, commandType: CommandType.StoredProcedure);
|
||||
return rows.ToList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user