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();
|
||||
}
|
||||
}
|
||||
15
EmployeeLibrary/EmployeeLibrary.csproj
Normal file
15
EmployeeLibrary/EmployeeLibrary.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.0.151" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
9
EmployeeLibrary/Models/EmployeeModel.cs
Normal file
9
EmployeeLibrary/Models/EmployeeModel.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace EmployeeLibrary.Models;
|
||||
|
||||
public class EmployeeModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? FirstName { get; set; }
|
||||
public string? LastName { get; set; }
|
||||
public string? Title { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user