Files
laatzen/LaaProductionWeb/LaaProduction.Personalization/Repositories/RolesRepository.cs
T
2023-06-16 11:29:11 +02:00

49 lines
1.8 KiB
C#

namespace LaaProduction.Personalization.Repositories
{
using LaaProduction.Personalization.Repositories.Interfaces;
using LaaProductionSQL.Interfaces;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
public class RolesRepository : IRolesRepository
{
private readonly ISQLConnection sqlConnection;
public RolesRepository(ISQLConnection sqlConnection)
=> this.sqlConnection = sqlConnection;
public IEnumerable<string> All()
=> this.sqlConnection
.CreateCommand(@"
SELECT DISTINCT [Recht]
FROM [MitarbeiterRechte]")
.ExecuteReader(x => x.GetString());
public IEnumerable<string> All(short employeeId)
=> this.sqlConnection
.CreateCommand($@"
SELECT DISTINCT [Recht]
FROM [MitarbeiterRechte]
WHERE [MitarbeiterNr] = @{nameof(employeeId)}")
.SetParameter(nameof(employeeId), employeeId)
.ExecuteReader(x => x.GetString());
public void Delete(short employeeId)
=> this.sqlConnection
.CreateCommand($@"
DELETE FROM [MitarbeiterRechte]
WHERE [MitarbeiterNr] = @{nameof(employeeId)}")
.SetParameter(nameof(employeeId), employeeId)
.ExecuteNonQuery();
public void Insert(short employeeId, IEnumerable<string> roles)
=> this.sqlConnection
.CreateCommand($@"
INSERT INTO [MitarbeiterRechte] ([MitarbeiterNr], [Recht])
VALUES {string.Join(", ", roles.Select((x, i) => $"('{employeeId}', '{new SqlParameter(i.ToString(), x).SqlValue}')"))}")
.ExecuteNonQuery();
}
}