Start of Datenbank
This commit is contained in:
24
DataAccess/Data/BildInfoData.cs
Normal file
24
DataAccess/Data/BildInfoData.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DataAccess.DbAccess;
|
||||
using DataAccess.Models;
|
||||
|
||||
namespace DataAccess.Data;
|
||||
|
||||
public class BildInfoData
|
||||
{
|
||||
private readonly ISqlDataAccess _db;
|
||||
|
||||
public BildInfoData(ISqlDataAccess db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public async Task AddBildInfo(BildInfoModel bildInfo)
|
||||
{
|
||||
await _db.SaveData("dbo.spBildInfo_Insert", bildInfo);
|
||||
}
|
||||
}
|
||||
15
DataAccess/DataAccess.csproj
Normal file
15
DataAccess/DataAccess.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.1.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
7
DataAccess/DbAccess/ISqlDataAccess.cs
Normal file
7
DataAccess/DbAccess/ISqlDataAccess.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace DataAccess.DbAccess;
|
||||
|
||||
public interface ISqlDataAccess
|
||||
{
|
||||
Task<IEnumerable<T>> LoadData<T, U>(string storedProcedure, U parameters, string connectionId = "Default");
|
||||
Task SaveData<T>(string storedProcedure, T parameters, string connectionId = "Default");
|
||||
}
|
||||
30
DataAccess/DbAccess/SqlDataAccess.cs
Normal file
30
DataAccess/DbAccess/SqlDataAccess.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using Dapper;
|
||||
|
||||
namespace DataAccess.DbAccess;
|
||||
|
||||
public class SqlDataAccess : ISqlDataAccess
|
||||
{
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public SqlDataAccess(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<T>> LoadData<T, U>(string storedProcedure, U parameters, string connectionId = "Default")
|
||||
{
|
||||
using IDbConnection connection = new SqlConnection(_config.GetConnectionString(connectionId));
|
||||
|
||||
return await connection.QueryAsync<T>(storedProcedure, parameters, commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
|
||||
public async Task SaveData<T>(string storedProcedure, T parameters, string connectionId = "Default")
|
||||
{
|
||||
using IDbConnection connection = new SqlConnection(_config.GetConnectionString(connectionId));
|
||||
|
||||
await connection.ExecuteAsync(storedProcedure, parameters, commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
}
|
||||
14
DataAccess/Models/BildInfoModel.cs
Normal file
14
DataAccess/Models/BildInfoModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace DataAccess.Models;
|
||||
|
||||
public class BildInfoModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string BildPrompt { get; set; }
|
||||
public string Wunsch { get; set; }
|
||||
public string BildBeschreibung { get; set; }
|
||||
public DateTime Datum { get; set; }
|
||||
public string Dateiname { get; set; }
|
||||
public string GPTModel { get; set; }
|
||||
public string ImageModel { get; set; }
|
||||
public int GroupIndex { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user