43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
namespace LaaProductionWeb.Blazor.Components.CSD.Data
|
|
{
|
|
using LaaPackages.SqlClient;
|
|
using LaaProductionWeb.Blazor.Components.Logging.Sqlite;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
public class CSDDBContext
|
|
{
|
|
private readonly SqlConnection connection;
|
|
private readonly SqliteLoggingDbContext sqliteLogging;
|
|
|
|
public CSDDBContext(IConfiguration configuration, SqliteLoggingDbContext sqliteLogging)
|
|
{
|
|
var connectionString = configuration.GetConnectionString("Auftrag");
|
|
this.connection = SqlConnection.CreateSqlConnection(connectionString, this.LogSqlErrors);
|
|
}
|
|
|
|
public IEnumerable<string> GetBasisCodes()
|
|
=> this.connection
|
|
.CreateCommand(@"
|
|
SELECT DISTINCT vmm.Basis
|
|
FROM VAKO_Merkmale AS vmm
|
|
WHERE vmm.Basis IS NOT NULL
|
|
ORDER BY 1")
|
|
.ExecuteReader(x => x.GetValue<string>(0));
|
|
|
|
private void LogSqlErrors(string message)
|
|
=> this.sqliteLogging.Add(new SqliteLog
|
|
{
|
|
DateTime = DateTime.Now,
|
|
EventName = "SQL Error",
|
|
EventSource = nameof(CSDDBContext),
|
|
LogLevel = nameof(LogLevel.Error),
|
|
Message = message
|
|
});
|
|
}
|
|
}
|