Add project files.

This commit is contained in:
2023-10-02 08:24:46 +02:00
parent 24735dd117
commit e1c0b7b113
98 changed files with 75000 additions and 0 deletions

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

View File

@ -0,0 +1,9 @@
using EmployeeLibrary.Models;
namespace EmployeeLibrary.Data
{
public interface IEmployeeData
{
Task<List<EmployeeModel>> GetEmployees();
}
}

View File

@ -0,0 +1,7 @@
namespace EmployeeLibrary.Data
{
public interface ISqlDataAccess
{
Task<List<T>> LoadDataAsync<T, U>(string sql, U parameters, string connectionStringName = "Default");
}
}

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

View 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>

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