73 lines
3.2 KiB
C#
73 lines
3.2 KiB
C#
namespace LaaProduction.Personalization.Repositories
|
|
{
|
|
using LaaProduction.Personalization.Models;
|
|
using LaaProduction.Personalization.Repositories.Interfaces;
|
|
using LaaProductionSQL.Interfaces;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
internal class SoftwareRepository : ISoftwareRepository
|
|
{
|
|
private readonly ISQLConnection sqlConnection;
|
|
|
|
public SoftwareRepository(ISQLConnection sqlConnection)
|
|
=> this.sqlConnection = sqlConnection;
|
|
|
|
public short AppId(string software)
|
|
=> this.sqlConnection
|
|
.CreateCommand($@"
|
|
SELECT [AppID]
|
|
FROM [VersionSoftwareAccess]
|
|
WHERE [SoftwareAccess_Program] = @{nameof(software)}")
|
|
.SetParameter(nameof(software), software)
|
|
.FirstOrDefault(x => x.GetSmallint());
|
|
|
|
public IEnumerable<string> GetSoftwareFunctions(string token)
|
|
=> this.sqlConnection
|
|
.CreateCommand($@"
|
|
SELECT [SF].[Function]
|
|
FROM [MitarbeiterTokens] AS [MT]
|
|
JOIN [SoftwareFunctions] AS [SF]
|
|
ON [SF].[AppId] = [MT].[AppId]
|
|
WHERE [MT].[Token] = @{nameof(token)}")
|
|
.SetParameter(nameof(token), token)
|
|
.ExecuteReader(x => x.GetString());
|
|
|
|
public IEnumerable<SoftwareItem> List()
|
|
=> this.sqlConnection
|
|
.CreateCommand($@"
|
|
SELECT [Software].[SoftwareId]
|
|
, [Software].[AssemblyName]
|
|
, [Software].[MajorV]
|
|
, [Software].[MinorV]
|
|
, [Software].[Build]
|
|
, [Software].[VersionId]
|
|
, [Software].[ValidUntil]
|
|
, [Software].[Description]
|
|
FROM (SELECT [AppID] AS [SoftwareId]
|
|
, [SoftwareAccess_Program] AS [AssemblyName]
|
|
, [SoftwareAccess_MajorVersion] AS [MajorV]
|
|
, [SoftwareAccess_MinorVersion] AS [MinorV]
|
|
, [SoftwareAccess_BuildVersion] AS [Build]
|
|
, [SoftwareAccess_ID] AS [VersionId]
|
|
, [SoftwareAccess_VaildTo] AS [ValidUntil]
|
|
, [SoftwareAccess_Desc] AS [Description]
|
|
, ROW_NUMBER()
|
|
OVER (PARTITION BY [AppID]
|
|
ORDER BY [SoftwareAccess_VaildTo] DESC) AS [RowNumber]
|
|
FROM [VersionSoftwareAccess])
|
|
AS [Software]
|
|
WHERE [Software].[RowNumber] <= 1
|
|
ORDER BY [Software].[AssemblyName]")
|
|
.ExecuteReader(x => new SoftwareItem
|
|
{
|
|
SoftwareId = x.GetSmallint(),
|
|
AssemblyName = x.GetString(),
|
|
CurrentVersion = $"{x.GetInt()}.{x.GetInt()}.{x.GetInt()}",
|
|
VersionId = x.GetInt(),
|
|
ValidUntil = $"{x.GetDate():yyyy-MM-dd}",
|
|
Description = x.GetString(),
|
|
});
|
|
}
|
|
}
|