employees edit form
This commit is contained in:
+50
-51
@@ -17,33 +17,16 @@
|
||||
public IEnumerable<Employee> All()
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT DISTINCT
|
||||
[E].[EmployeeId] AS [EmployeeId]
|
||||
, [E].[FullName] AS [FullName]
|
||||
, [E].[Username] AS [Username]
|
||||
, [E].[RolesCount] AS [RolesCount]
|
||||
, COUNT([UF].[SoftwareFunctionId])
|
||||
OVER (PARTITION BY [E].[EmployeeId]) AS [FunctionsCount]
|
||||
FROM (SELECT DISTINCT
|
||||
[M].[MitarbeiterNr] AS [EmployeeId]
|
||||
, [M].[Vorname] + ' ' + [M].[Name] AS [FullName]
|
||||
, [M].[Benutzername] AS [Username]
|
||||
, COUNT([MR].[Recht])
|
||||
OVER (PARTITION BY [M].[MitarbeiterNr]) AS [RolesCount]
|
||||
FROM [Mitarbeiter] AS [M]
|
||||
LEFT JOIN [MitarbeiterRechte] AS [MR]
|
||||
ON [MR].[MitarbeiterNr] = [M].[MitarbeiterNr])
|
||||
AS [E]
|
||||
LEFT JOIN [UsersFunctions] AS [UF]
|
||||
ON [UF].[UserId] = [E].[EmployeeId]
|
||||
ORDER BY [E].[FullName]")
|
||||
SELECT [M].[MitarbeiterNr] AS [EmployeeId]
|
||||
, [M].[Vorname] + ' ' + [M].[Name] AS [FullName]
|
||||
, [M].[Benutzername] AS [Username]
|
||||
FROM [Mitarbeiter] AS [M]
|
||||
ORDER BY [FullName], [Username]")
|
||||
.ExecuteReader(x => new Employee
|
||||
{
|
||||
EmployeeId = x.GetSmallint(),
|
||||
FullName = x.GetString(),
|
||||
Username = x.GetString(),
|
||||
RolesCount = x.GetInt(),
|
||||
FunctionsCount = x.GetInt()
|
||||
});
|
||||
|
||||
public void CreateToken(short appId, short userId)
|
||||
@@ -72,35 +55,19 @@
|
||||
public Employee Find(short employeeId)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT DISTINCT
|
||||
[E].[EmployeeId] AS [EmployeeId]
|
||||
, [E].[FullName] AS [FullName]
|
||||
, [E].[Username] AS [Username]
|
||||
, [E].[RolesCount] AS [RolesCount]
|
||||
, COUNT([UF].[SoftwareFunctionId])
|
||||
OVER (PARTITION BY [E].[EmployeeId]) AS [FunctionsCount]
|
||||
FROM (SELECT DISTINCT
|
||||
[M].[MitarbeiterNr] AS [EmployeeId]
|
||||
, [M].[Vorname] + ' ' + [M].[Name] AS [FullName]
|
||||
, [M].[Benutzername] AS [Username]
|
||||
, COUNT([MR].[Recht])
|
||||
OVER (PARTITION BY [M].[MitarbeiterNr]) AS [RolesCount]
|
||||
FROM [Mitarbeiter] AS [M]
|
||||
LEFT JOIN [MitarbeiterRechte] AS [MR]
|
||||
ON [MR].[MitarbeiterNr] = [M].[MitarbeiterNr]
|
||||
WHERE [M].[MitarbeiterNr] = @{nameof(employeeId)})
|
||||
AS [E]
|
||||
LEFT JOIN [UsersFunctions] AS [UF]
|
||||
ON [UF].[UserId] = [E].[EmployeeId]
|
||||
ORDER BY [E].[FullName]")
|
||||
SELECT [M].[MitarbeiterNr] AS [EmployeeId]
|
||||
, [M].[Vorname] + ' ' + [M].[Name] AS [FullName]
|
||||
, [M].[Benutzername] AS [Username]
|
||||
, [M].[PasswordHash] AS [Password]
|
||||
FROM [Mitarbeiter] AS [M]
|
||||
WHERE [M].[MitarbeiterNr] = @{nameof(employeeId)}")
|
||||
.SetParameter(nameof(employeeId), employeeId)
|
||||
.FirstOrDefault(x => new Employee
|
||||
{
|
||||
EmployeeId = x.GetSmallint(),
|
||||
FullName = x.GetString(),
|
||||
Username = x.GetString(),
|
||||
RolesCount = x.GetInt(),
|
||||
FunctionsCount = x.GetInt()
|
||||
HasPassword = x.GetString() != null
|
||||
});
|
||||
|
||||
public Employee GetEmployee(string token)
|
||||
@@ -132,6 +99,20 @@
|
||||
.SetParameter(nameof(userId), userId)
|
||||
.FirstOrDefault(x => x.GetString());
|
||||
|
||||
public EmployeeToken GetTokenData(string token)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT [AppId]
|
||||
, [UserId]
|
||||
FROM [MitarbeiterTokens]
|
||||
WHERE [Token] = @{nameof(token)}")
|
||||
.SetParameter(nameof(token), token)
|
||||
.FirstOrDefault(x => new EmployeeToken
|
||||
{
|
||||
AppId = x.GetSmallint(),
|
||||
EmployeeId = x.GetSmallint()
|
||||
});
|
||||
|
||||
public IEnumerable<string> GetUserRoles(string token)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
@@ -143,13 +124,31 @@
|
||||
.SetParameter(nameof(token), token)
|
||||
.ExecuteReader(x => x.GetString());
|
||||
|
||||
public bool TokenExists(string token)
|
||||
public void ResetPassword(short employeeId)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT COUNT(1)
|
||||
FROM [MitarbeiterTokens]
|
||||
WHERE [Token] = @{nameof(token)}")
|
||||
.SetParameter(nameof(token), token)
|
||||
.FirstOrDefault(x => x.GetInt() > 0);
|
||||
UPDATE [Mitarbeiter]
|
||||
SET [PasswordHash] = NULL
|
||||
WHERE [MitarbeiterNr] = @{nameof(employeeId)}")
|
||||
.SetParameter(nameof(employeeId), employeeId)
|
||||
.ExecuteNonQuery();
|
||||
|
||||
public void ResetTokens(short employeeId)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
DELETE FROM [MitarbeiterTokens]
|
||||
WHERE [UserId] = @{nameof(employeeId)}")
|
||||
.SetParameter(nameof(employeeId), employeeId)
|
||||
.ExecuteNonQuery();
|
||||
|
||||
public void SetPassword(short employeeId, string password)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
UPDATE [Mitarbeiter]
|
||||
SET [PasswordHash] = @{nameof(password)}
|
||||
WHERE [MitarbeiterNr] = @{nameof(employeeId)}")
|
||||
.SetParameter(nameof(employeeId), employeeId)
|
||||
.SetParameter(nameof(password), password)
|
||||
.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
namespace LaaProduction.Personalization.Repositories
|
||||
{
|
||||
using LaaProduction.Personalization.Repositories.Interfaces;
|
||||
using LaaProductionSQL.Interfaces;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
internal class FunctionsRepository : IFunctionsRepository
|
||||
{
|
||||
private readonly ISQLConnection sqlConnection;
|
||||
|
||||
public FunctionsRepository(ISQLConnection sqlConnection)
|
||||
=> this.sqlConnection = sqlConnection;
|
||||
|
||||
public IEnumerable<string> All()
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT DISTINCT [SF].[Function]
|
||||
FROM [SoftwareFunctions] AS [SF]")
|
||||
.ExecuteReader(x => x.GetString());
|
||||
|
||||
public IEnumerable<string> All(short appId)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT [SF].[Function]
|
||||
FROM [SoftwareFunctions] AS [SF]
|
||||
WHERE [SF].[AppId] = @{nameof(appId)}")
|
||||
.SetParameter(nameof(appId), appId)
|
||||
.ExecuteReader(x => x.GetString());
|
||||
|
||||
public void Delete(short employeeId)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
DELETE FROM [UsersFunctions]
|
||||
WHERE [UserId] = @{nameof(employeeId)}")
|
||||
.SetParameter(nameof(employeeId), employeeId)
|
||||
.ExecuteNonQuery();
|
||||
|
||||
public IEnumerable<string> EmployeeAll(short employeeId)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT [SF].[Function]
|
||||
FROM [UsersFunctions] AS [UF]
|
||||
JOIN [SoftwareFunctions] AS [SF]
|
||||
ON [SF].[Id] = [UF].[SoftwareFunctionId]
|
||||
WHERE [UF].[UserId] = @{nameof(employeeId)}")
|
||||
.SetParameter(nameof(employeeId), employeeId)
|
||||
.ExecuteReader(x => x.GetString());
|
||||
|
||||
public void Insert(short employeeId, IEnumerable<string> functions)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
INSERT INTO [UsersFunctions] (
|
||||
[UserId]
|
||||
, [SoftwareFunctionId])
|
||||
SELECT @{nameof(employeeId)}
|
||||
, [Id]
|
||||
FROM [SoftwareFunctions]
|
||||
WHERE [Function] IN ({string.Join(", ", functions.Select(x => $"'{x}'"))})")
|
||||
.SetParameter(nameof(employeeId), employeeId)
|
||||
.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
+7
-1
@@ -18,8 +18,14 @@
|
||||
|
||||
string GetToken(short appId, short userId);
|
||||
|
||||
EmployeeToken GetTokenData(string token);
|
||||
|
||||
IEnumerable<string> GetUserRoles(string token);
|
||||
|
||||
bool TokenExists(string token);
|
||||
void ResetPassword(short employeeId);
|
||||
|
||||
void ResetTokens(short employeeId);
|
||||
|
||||
void SetPassword(short employeeId, string password);
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
namespace LaaProduction.Personalization.Repositories.Interfaces
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
internal interface IFunctionsRepository
|
||||
{
|
||||
IEnumerable<string> All();
|
||||
|
||||
IEnumerable<string> All(short appId);
|
||||
|
||||
void Delete(short employeeId);
|
||||
|
||||
IEnumerable<string> EmployeeAll(short employeeId);
|
||||
|
||||
void Insert(short employeeId, IEnumerable<string> functions);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -2,11 +2,11 @@
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
public interface IRolesRepository
|
||||
internal interface IRolesRepository
|
||||
{
|
||||
IEnumerable<string> All();
|
||||
|
||||
IEnumerable<KeyValuePair<string, bool>> All(short employeeId);
|
||||
IEnumerable<string> All(short employeeId);
|
||||
|
||||
void Delete(short employeeId);
|
||||
|
||||
|
||||
@@ -21,18 +21,14 @@
|
||||
FROM [MitarbeiterRechte]")
|
||||
.ExecuteReader(x => x.GetString());
|
||||
|
||||
public IEnumerable<KeyValuePair<string, bool>> All(short employeeId)
|
||||
public IEnumerable<string> All(short employeeId)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT DISTINCT
|
||||
[AllRoles].[Recht]
|
||||
, CAST(CASE WHEN [UsrRoles].[MitarbeiterNr] IS NULL THEN 0 ELSE 1 END AS BIT)
|
||||
FROM [MitarbeiterRechte] AS [AllRoles]
|
||||
LEFT JOIN [MitarbeiterRechte] AS [UsrRoles]
|
||||
ON [UsrRoles].[Recht] = [AllRoles].[Recht]
|
||||
AND [UsrRoles].[MitarbeiterNr] = @{nameof(employeeId)}")
|
||||
SELECT DISTINCT [Recht]
|
||||
FROM [MitarbeiterRechte]
|
||||
WHERE [MitarbeiterNr] = @{nameof(employeeId)}")
|
||||
.SetParameter(nameof(employeeId), employeeId)
|
||||
.ExecuteReader(x => new KeyValuePair<string, bool>(x.GetString(), x.GetBool()));
|
||||
.ExecuteReader(x => x.GetString());
|
||||
|
||||
public void Delete(short employeeId)
|
||||
=> this.sqlConnection
|
||||
|
||||
Reference in New Issue
Block a user