diff --git a/DataAccess/Data/BildInfoData.cs b/DataAccess/Data/BildInfoData.cs
new file mode 100644
index 0000000..5756895
--- /dev/null
+++ b/DataAccess/Data/BildInfoData.cs
@@ -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);
+ }
+}
diff --git a/DataAccess/DataAccess.csproj b/DataAccess/DataAccess.csproj
new file mode 100644
index 0000000..810ea4c
--- /dev/null
+++ b/DataAccess/DataAccess.csproj
@@ -0,0 +1,15 @@
+
+
+
+ net7.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
diff --git a/DataAccess/DbAccess/ISqlDataAccess.cs b/DataAccess/DbAccess/ISqlDataAccess.cs
new file mode 100644
index 0000000..ed3232e
--- /dev/null
+++ b/DataAccess/DbAccess/ISqlDataAccess.cs
@@ -0,0 +1,7 @@
+namespace DataAccess.DbAccess;
+
+public interface ISqlDataAccess
+{
+ Task> LoadData(string storedProcedure, U parameters, string connectionId = "Default");
+ Task SaveData(string storedProcedure, T parameters, string connectionId = "Default");
+}
\ No newline at end of file
diff --git a/DataAccess/DbAccess/SqlDataAccess.cs b/DataAccess/DbAccess/SqlDataAccess.cs
new file mode 100644
index 0000000..f8d323d
--- /dev/null
+++ b/DataAccess/DbAccess/SqlDataAccess.cs
@@ -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> LoadData(string storedProcedure, U parameters, string connectionId = "Default")
+ {
+ using IDbConnection connection = new SqlConnection(_config.GetConnectionString(connectionId));
+
+ return await connection.QueryAsync(storedProcedure, parameters, commandType: CommandType.StoredProcedure);
+ }
+
+ public async Task SaveData(string storedProcedure, T parameters, string connectionId = "Default")
+ {
+ using IDbConnection connection = new SqlConnection(_config.GetConnectionString(connectionId));
+
+ await connection.ExecuteAsync(storedProcedure, parameters, commandType: CommandType.StoredProcedure);
+ }
+}
diff --git a/DataAccess/Models/BildInfoModel.cs b/DataAccess/Models/BildInfoModel.cs
new file mode 100644
index 0000000..c46d93c
--- /dev/null
+++ b/DataAccess/Models/BildInfoModel.cs
@@ -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; }
+}
diff --git a/KIKunstKirstenKlöckner.sln b/KIKunstKirstenKlöckner.sln
index ff37735..8d4d872 100644
--- a/KIKunstKirstenKlöckner.sln
+++ b/KIKunstKirstenKlöckner.sln
@@ -5,6 +5,10 @@ VisualStudioVersion = 17.6.33829.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KIKunstKirstenKlöckner", "KIKunstKirstenKlöckner\KIKunstKirstenKlöckner.csproj", "{0085541E-50D4-42A5-9BFD-6CE402FB8B26}"
EndProject
+Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "KiKunstDatenbank", "KiKunstDatenbank\KiKunstDatenbank.sqlproj", "{A19CD19A-FE5B-4D4E-896B-DCC43B45F734}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataAccess", "DataAccess\DataAccess.csproj", "{0880FD07-236B-42C1-9CA3-2A6F695A623C}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +19,16 @@ Global
{0085541E-50D4-42A5-9BFD-6CE402FB8B26}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0085541E-50D4-42A5-9BFD-6CE402FB8B26}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0085541E-50D4-42A5-9BFD-6CE402FB8B26}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A19CD19A-FE5B-4D4E-896B-DCC43B45F734}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A19CD19A-FE5B-4D4E-896B-DCC43B45F734}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A19CD19A-FE5B-4D4E-896B-DCC43B45F734}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
+ {A19CD19A-FE5B-4D4E-896B-DCC43B45F734}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A19CD19A-FE5B-4D4E-896B-DCC43B45F734}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A19CD19A-FE5B-4D4E-896B-DCC43B45F734}.Release|Any CPU.Deploy.0 = Release|Any CPU
+ {0880FD07-236B-42C1-9CA3-2A6F695A623C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0880FD07-236B-42C1-9CA3-2A6F695A623C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0880FD07-236B-42C1-9CA3-2A6F695A623C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0880FD07-236B-42C1-9CA3-2A6F695A623C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/KIKunstKirstenKlöckner/.config/dotnet-tools.json b/KIKunstKirstenKlöckner/.config/dotnet-tools.json
new file mode 100644
index 0000000..2be6730
--- /dev/null
+++ b/KIKunstKirstenKlöckner/.config/dotnet-tools.json
@@ -0,0 +1,12 @@
+{
+ "version": 1,
+ "isRoot": true,
+ "tools": {
+ "dotnet-ef": {
+ "version": "7.0.9",
+ "commands": [
+ "dotnet-ef"
+ ]
+ }
+ }
+}
\ No newline at end of file
diff --git a/KIKunstKirstenKlöckner/KIKunstKirstenKlöckner.csproj b/KIKunstKirstenKlöckner/KIKunstKirstenKlöckner.csproj
index 03f043e..3c666a9 100644
--- a/KIKunstKirstenKlöckner/KIKunstKirstenKlöckner.csproj
+++ b/KIKunstKirstenKlöckner/KIKunstKirstenKlöckner.csproj
@@ -20,4 +20,8 @@
+
+
+
+
diff --git a/KIKunstKirstenKlöckner/Pages/AiArt.razor b/KIKunstKirstenKlöckner/Pages/AiArt.razor
index a2723d6..77be345 100644
--- a/KIKunstKirstenKlöckner/Pages/AiArt.razor
+++ b/KIKunstKirstenKlöckner/Pages/AiArt.razor
@@ -4,11 +4,15 @@
@using OpenAI_API.Chat
@using OpenAI_API.Models
@using System.Diagnostics
+@using DataAccess.Data
+@using DataAccess.Models
@inject IConfiguration Config
@inject TooltipService TooltipService
@inject DialogService DialogService
+@inject BildInfoData BildInfoData;
+
AiArt
@@ -244,7 +248,7 @@
private string _inferenceApiKey = "";
private string _openAiApiKey = "";
- protected override Task OnInitializedAsync()
+ protected override async Task OnInitializedAsync()
{
_inferenceApiKey = Config.GetValue("API:HF_Inference");
_openAiApiKey = Config.GetValue("API:OpenAI");
@@ -258,7 +262,31 @@
_client.DefaultRequestHeaders.Clear();
_client.DefaultRequestHeaders.Add("Authorization", $"Bearer {_inferenceApiKey}");
- return base.OnInitializedAsync();
+
+ BildInfoModel bildInfo = new()
+ {
+ BildBeschreibung = "Test",
+ BildPrompt = "Tost",
+ Dateiname = "Task",
+ Datum = DateTime.Now,
+ GPTModel = "Geht dich nichts an",
+ ImageModel = "Jup",
+ Wunsch = request
+ };
+
+ try
+ {
+
+ await BildInfoData.AddBildInfo(bildInfo);
+
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e);
+ throw;
+ }
+
+ await base.OnInitializedAsync();
}
///
@@ -372,7 +400,9 @@
using Image image = await Image.LoadAsync(imageStream);
- string imgUrl = $"generated_images/{DateTime.Now:dd_MM_yyyy_hh_mm_s_fffffff}.jpg";
+ DateTime imageDate = DateTime.Now;
+
+ string imgUrl = $"generated_images/{imageDate:dd_MM_yyyy_hh_mm_s_fffffff}.jpg";
string mapPath = $"./wwwroot/{imgUrl}";
await image.SaveAsJpegAsync(mapPath);
@@ -383,6 +413,19 @@
string newLine = $"{imgUrl}: {request}, {desc}\n";
await File.AppendAllTextAsync(infoTextsPath, newLine);
+ BildInfoModel bildInfo = new()
+ {
+ BildBeschreibung = desc,
+ BildPrompt = prompt,
+ Dateiname = imgUrl,
+ Datum = imageDate,
+ GPTModel = "Geht dich nichts an",
+ ImageModel = "Jup",
+ Wunsch = request
+ };
+
+ await BildInfoData.AddBildInfo(bildInfo);
+
return imgUrl;
}
else
diff --git a/KIKunstKirstenKlöckner/Program.cs b/KIKunstKirstenKlöckner/Program.cs
index 12038c0..4677e7d 100644
--- a/KIKunstKirstenKlöckner/Program.cs
+++ b/KIKunstKirstenKlöckner/Program.cs
@@ -1,3 +1,5 @@
+using DataAccess.Data;
+using DataAccess.DbAccess;
using Radzen;
var builder = WebApplication.CreateBuilder(args);
@@ -8,6 +10,8 @@ builder.Services.AddServerSideBlazor();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
+builder.Services.AddSingleton();
+builder.Services.AddSingleton();
var app = builder.Build();
diff --git a/KIKunstKirstenKlöckner/appsettings.Development.json b/KIKunstKirstenKlöckner/appsettings.Development.json
index 770d3e9..fab8beb 100644
--- a/KIKunstKirstenKlöckner/appsettings.Development.json
+++ b/KIKunstKirstenKlöckner/appsettings.Development.json
@@ -1,9 +1,12 @@
{
- "DetailedErrors": true,
- "Logging": {
- "LogLevel": {
- "Default": "Information",
- "Microsoft.AspNetCore": "Warning"
+ "DetailedErrors": true,
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ },
+ "ConnectionStrings": {
+ "Default": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=KiKunstDatenbank;Integrated Security=True;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
}
- }
}
diff --git a/KIKunstKirstenKlöckner/appsettings.json b/KIKunstKirstenKlöckner/appsettings.json
index 1f5d6fd..0d8c4f9 100644
--- a/KIKunstKirstenKlöckner/appsettings.json
+++ b/KIKunstKirstenKlöckner/appsettings.json
@@ -9,5 +9,8 @@
"API": {
"OpenAI": "",
"HF_Inference": ""
+ },
+ "ConnectionStrings": {
+ "Default": ""
}
}
diff --git a/KiKunstDatenbank/KiKunstDatenbank.refactorlog b/KiKunstDatenbank/KiKunstDatenbank.refactorlog
new file mode 100644
index 0000000..004b191
--- /dev/null
+++ b/KiKunstDatenbank/KiKunstDatenbank.refactorlog
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/KiKunstDatenbank/KiKunstDatenbank.sqlproj b/KiKunstDatenbank/KiKunstDatenbank.sqlproj
new file mode 100644
index 0000000..c72c853
--- /dev/null
+++ b/KiKunstDatenbank/KiKunstDatenbank.sqlproj
@@ -0,0 +1,76 @@
+
+
+
+ Debug
+ AnyCPU
+ KiKunstDatenbank
+ 2.0
+ 4.1
+ {a19cd19a-fe5b-4d4e-896b-dcc43b45f734}
+ Microsoft.Data.Tools.Schema.Sql.Sql150DatabaseSchemaProvider
+ Database
+
+
+ KiKunstDatenbank
+ KiKunstDatenbank
+ 1033, CI
+ BySchemaAndSchemaType
+ True
+ v4.7.2
+ CS
+ Properties
+ False
+ True
+ True
+
+
+ bin\Release\
+ $(MSBuildProjectName).sql
+ False
+ pdbonly
+ true
+ false
+ true
+ prompt
+ 4
+
+
+ bin\Debug\
+ $(MSBuildProjectName).sql
+ false
+ true
+ full
+ false
+ true
+ true
+ prompt
+ 4
+
+
+ 11.0
+
+ True
+ 11.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/KiKunstDatenbank/Script.PostDeployment.sql b/KiKunstDatenbank/Script.PostDeployment.sql
new file mode 100644
index 0000000..cf6c8e4
--- /dev/null
+++ b/KiKunstDatenbank/Script.PostDeployment.sql
@@ -0,0 +1,19 @@
+/*
+Vorlage für ein Skript nach der Bereitstellung
+--------------------------------------------------------------------------------------
+ Diese Datei enthält SQL-Anweisungen, die an das Buildskript angefügt werden.
+ Schließen Sie mit der SQLCMD-Syntax eine Datei in das Skript nach der Bereitstellung ein.
+ Beispiel: :r .\myfile.sql
+ Verwenden Sie die SQLCMD-Syntax, um auf eine Variable im Skript nach der Bereitstellung zu verweisen.
+ Beispiel: :setvar TableName MyTable
+ SELECT * FROM [$(TableName)]
+--------------------------------------------------------------------------------------
+*/
+--IF NOT EXISTS (SELECT 1 FROM [dbo].[User])
+--BEGIN
+-- INSERT INTO [dbo].[User] (FirstName, LastName)
+-- VALUES ('Simon', 'Lübeß'),
+-- ('Peter', 'Enis'),
+-- ('John', 'Smith'),
+-- ('Mary', 'Jones')
+--END
diff --git a/KiKunstDatenbank/dpo/StoredProcedures/spBildInfo_Insert.sql b/KiKunstDatenbank/dpo/StoredProcedures/spBildInfo_Insert.sql
new file mode 100644
index 0000000..eb8293c
--- /dev/null
+++ b/KiKunstDatenbank/dpo/StoredProcedures/spBildInfo_Insert.sql
@@ -0,0 +1,22 @@
+CREATE PROCEDURE [dbo].[spBildInfo_Insert]
+ @Id INT,
+ @BildPrompt NVARCHAR(MAX) ,
+ @Wunsch NVARCHAR(1024) ,
+ @BildBeschreibung NVARCHAR(MAX) ,
+ @Datum DATETIME2 ,
+ @Dateiname NCHAR(256) ,
+ @GPTModel NCHAR(32) ,
+ @ImageModel NCHAR(32) ,
+ @GroupIndex INT
+AS
+BEGIN
+ INSERT INTO [dbo].[BildInfo] (BildPrompt, Wunsch, BildBeschreibung, Datum, Dateiname, GPTModel, ImageModel, GroupIndex)
+ VALUES (@BildPrompt,
+ @Wunsch,
+ @BildBeschreibung,
+ @Datum,
+ @Dateiname,
+ @GPTModel,
+ @ImageModel,
+ @GroupIndex);
+END
\ No newline at end of file
diff --git a/KiKunstDatenbank/dpo/Tables/BildInfo.sql b/KiKunstDatenbank/dpo/Tables/BildInfo.sql
new file mode 100644
index 0000000..a5a351b
--- /dev/null
+++ b/KiKunstDatenbank/dpo/Tables/BildInfo.sql
@@ -0,0 +1,22 @@
+CREATE TABLE [dbo].[BildInfo]
+(
+ [Id] INT NOT NULL PRIMARY KEY IDENTITY,
+ [BildPrompt] NVARCHAR(MAX) NOT NULL,
+ [Wunsch] NVARCHAR(1024) NOT NULL,
+ [BildBeschreibung] NVARCHAR(MAX) NOT NULL,
+ [Datum] DATETIME2 NOT NULL,
+ [Dateiname] NCHAR(256) NOT NULL,
+ [GPTModel] NCHAR(32) NOT NULL,
+ [ImageModel] NCHAR(32) NOT NULL,
+ [GroupIndex] INT NOT NULL
+)
+
+GO
+EXEC sp_addextendedproperty @name = N'MS_Description',
+ @value = N'Index der Gruppe, in der dieses Bild generiert wurde und so.',
+ @level0type = N'SCHEMA',
+ @level0name = N'dbo',
+ @level1type = N'TABLE',
+ @level1name = N'BildInfo',
+ @level2type = N'COLUMN',
+ @level2name = 'GroupIndex'
\ No newline at end of file