From 6f9b448b330cc291f6f8f854717113b2c7f0acb5 Mon Sep 17 00:00:00 2001 From: Stoyan Zlatev Date: Thu, 15 Jun 2023 17:01:02 +0200 Subject: [PATCH] employees --- .../Models/Employee.cs | 11 -- .../Repositories/EmployeesRepository.cs | 89 ---------- .../AccountManager.cs} | 19 ++- .../EmployeesManager.cs | 46 ++++++ .../Interfaces/IAccountManager.cs} | 4 +- .../Interfaces/IEmployeesManager.cs | 17 ++ .../LaaProduction.Personalization.csproj} | 16 +- .../Models/Employee.cs | 15 ++ .../PersonalizationExtensions.cs} | 10 +- .../Properties/AssemblyInfo.cs | 0 .../README.md | 2 + .../Repositories/EmployeesRepository.cs | 155 ++++++++++++++++++ .../Interfaces/IEmployeesRepository.cs | 8 +- .../Interfaces/IRolesRepository.cs | 15 ++ .../Interfaces/ISoftwareRepository.cs | 2 +- .../Repositories/RolesRepository.cs | 52 ++++++ .../Repositories/SoftwareRepository.cs | 4 +- .../ServiceProvider.cs | 7 +- .../SoftwareFunctions.cs | 2 +- .../UsersRoles.cs} | 4 +- LaaProductionWeb/LaaProductionWeb.sln | 2 +- .../App_Content/css/styles.css | 21 +++ .../App_Content/js/scripts.js | 2 +- .../AllowedRolesAttribute.cs | 4 +- .../App_Infrastructure/AuthorizationFilter.cs | 4 +- .../AuthorizeBearerAttribute.cs | 28 ++++ .../App_Infrastructure/HttpExtensions.cs | 51 +++++- .../RouteParameterAttribute.cs | 41 +++++ .../App_Infrastructure/ServiceProvider.cs | 4 +- .../LaaProductionWeb/App_Start/RouteConfig.cs | 2 + .../App_Start/WebApiConfig.cs | 9 +- .../AdministrationAreaRegistration.cs | 17 -- .../Views/Shared/_Layout.cshtml | 53 ------ .../Views/Shared/_SoftwareSidebar.cshtml | 6 - .../Views/Software/SoftwareListGroup.cshtml | 13 -- .../Administration/Views/_ViewStart.cshtml | 3 - .../Controllers/EmployeesController.cs | 91 ++++++++++ .../EmployeesFunctionsController.cs | 14 ++ .../Controllers/EmployeesRolesController.cs | 14 ++ .../Controllers/PersonalizationController.cs | 14 ++ .../Controllers/SoftwareController.cs | 12 +- .../SoftwareFunctionsController.cs | 14 ++ .../Models/Employees/Employee.cs | 15 ++ .../Models/Employees/EmployeeEditModel.cs | 13 ++ .../Employees/EmployeeEditRolesModel.cs | 14 ++ .../Models/Employees/EmployeesListModel.cs | 11 ++ .../Models/Software/AddFunctionModel.cs | 2 +- .../Models/Software/EditFunctionModel.cs | 2 +- .../Software/FunctionUsersInputModel.cs | 2 +- .../Models/Software/SoftwareEditModel.cs | 2 +- .../Models/Software/SoftwareFunctionModel.cs | 2 +- .../Models/Software/SoftwareFunctionsModel.cs | 2 +- .../Models/Software/SoftwareModel.cs | 2 +- .../Models/Software/SoftwareOverviewModel.cs | 2 +- .../Models/Software/SoftwareUser.cs | 2 +- .../Models/Software/SoftwareVersionModel.cs | 2 +- .../Models/Software/SoftwareVersionsModel.cs | 2 +- .../Models/Software/UserFunctions.cs | 2 +- .../Software/UsersFunctionsInputModel.cs | 2 +- .../Models/Software/UsersFunctionsModel.cs | 2 +- .../PersonalizationAreaRegistration.cs | 22 +++ .../Views/Employees/Edit.cshtml | 86 ++++++++++ .../Views/Employees/Index.cshtml | 79 +++++++++ .../Views/EmployeesFunctions/Index.cshtml | 2 + .../Views/EmployeesRoles/Index.cshtml | 2 + .../Views/Personalization/Index.cshtml | 3 + .../Views/Shared/_Layout.cshtml | 64 ++++++++ .../Views/Shared/_SoftwareSidebar.cshtml | 6 + .../Views/Software/Index.cshtml | 14 +- .../Views/Software/SoftwareFunctions.cshtml | 20 +-- .../Views/Software/SoftwareListGroup.cshtml | 13 ++ .../Views/Software/SoftwareVersions.cshtml | 12 +- .../Views/Software/Users.cshtml | 19 ++- .../Views/Software/UsersFunctions.cshtml | 12 +- .../Views/SoftwareFunctions/Index.cshtml | 2 + .../Personalization/Views/_ViewStart.cshtml | 3 + .../Serach/Controllers/WildcardController.cs | 2 +- .../Software/Controllers/AppIdController.cs | 4 +- .../Controllers/FunctionsController.cs | 6 +- .../Personalization/EmployeesController.cs | 54 ++++++ .../LoginController.cs | 6 +- .../API/Personalization/RolesController.cs | 32 ++++ .../Controllers/AdminController.cs | 6 +- .../Controllers/ApprovalsController.cs | 10 +- .../Controllers/HomeController.cs | 8 +- .../Controllers/ProtocolController.cs | 6 +- .../Controllers/ReportController.cs | 6 +- .../Controllers/SearchController.cs | 8 +- .../Controllers/ShipmentsController.cs | 8 +- .../LaaProductionWeb/LaaProductionWeb.csproj | 79 +++++---- .../Views/Shared/_Layout.cshtml | 19 +-- 91 files changed, 1215 insertions(+), 376 deletions(-) delete mode 100644 LaaProductionWeb/LaaProduction.Administration/Models/Employee.cs delete mode 100644 LaaProductionWeb/LaaProduction.Administration/Repositories/EmployeesRepository.cs rename LaaProductionWeb/{LaaProduction.Administration/AccountManagement.cs => LaaProduction.Personalization/AccountManager.cs} (82%) create mode 100644 LaaProductionWeb/LaaProduction.Personalization/EmployeesManager.cs rename LaaProductionWeb/{LaaProduction.Administration/Interfaces/IAccountManagement.cs => LaaProduction.Personalization/Interfaces/IAccountManager.cs} (66%) create mode 100644 LaaProductionWeb/LaaProduction.Personalization/Interfaces/IEmployeesManager.cs rename LaaProductionWeb/{LaaProduction.Administration/LaaProduction.Administration.csproj => LaaProduction.Personalization/LaaProduction.Personalization.csproj} (89%) create mode 100644 LaaProductionWeb/LaaProduction.Personalization/Models/Employee.cs rename LaaProductionWeb/{LaaProduction.Administration/Extensions.cs => LaaProduction.Personalization/PersonalizationExtensions.cs} (63%) rename LaaProductionWeb/{LaaProduction.Administration => LaaProduction.Personalization}/Properties/AssemblyInfo.cs (100%) rename LaaProductionWeb/{LaaProduction.Administration => LaaProduction.Personalization}/README.md (78%) create mode 100644 LaaProductionWeb/LaaProduction.Personalization/Repositories/EmployeesRepository.cs rename LaaProductionWeb/{LaaProduction.Administration => LaaProduction.Personalization}/Repositories/Interfaces/IEmployeesRepository.cs (67%) create mode 100644 LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/IRolesRepository.cs rename LaaProductionWeb/{LaaProduction.Administration => LaaProduction.Personalization}/Repositories/Interfaces/ISoftwareRepository.cs (75%) create mode 100644 LaaProductionWeb/LaaProduction.Personalization/Repositories/RolesRepository.cs rename LaaProductionWeb/{LaaProduction.Administration => LaaProduction.Personalization}/Repositories/SoftwareRepository.cs (91%) rename LaaProductionWeb/{LaaProduction.Administration => LaaProduction.Personalization}/ServiceProvider.cs (76%) rename LaaProductionWeb/{LaaProduction.Administration => LaaProduction.Personalization}/SoftwareFunctions.cs (93%) rename LaaProductionWeb/{LaaProduction.Administration/UserRoles.cs => LaaProduction.Personalization/UsersRoles.cs} (95%) create mode 100644 LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizeBearerAttribute.cs create mode 100644 LaaProductionWeb/LaaProductionWeb/App_Infrastructure/RouteParameterAttribute.cs delete mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Administration/AdministrationAreaRegistration.cs delete mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Shared/_Layout.cshtml delete mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Shared/_SoftwareSidebar.cshtml delete mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Software/SoftwareListGroup.cshtml delete mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/_ViewStart.cshtml create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/EmployeesController.cs create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/EmployeesFunctionsController.cs create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/EmployeesRolesController.cs create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/PersonalizationController.cs rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Controllers/SoftwareController.cs (96%) create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/SoftwareFunctionsController.cs create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Employees/Employee.cs create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Employees/EmployeeEditModel.cs create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Employees/EmployeeEditRolesModel.cs create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Employees/EmployeesListModel.cs rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Models/Software/AddFunctionModel.cs (79%) rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Models/Software/EditFunctionModel.cs (82%) rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Models/Software/FunctionUsersInputModel.cs (75%) rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Models/Software/SoftwareEditModel.cs (73%) rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Models/Software/SoftwareFunctionModel.cs (72%) rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Models/Software/SoftwareFunctionsModel.cs (79%) rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Models/Software/SoftwareModel.cs (70%) rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Models/Software/SoftwareOverviewModel.cs (76%) rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Models/Software/SoftwareUser.cs (82%) rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Models/Software/SoftwareVersionModel.cs (89%) rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Models/Software/SoftwareVersionsModel.cs (74%) rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Models/Software/UserFunctions.cs (69%) rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Models/Software/UsersFunctionsInputModel.cs (75%) rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Models/Software/UsersFunctionsModel.cs (83%) create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/PersonalizationAreaRegistration.cs create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Employees/Edit.cshtml create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Employees/Index.cshtml create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/EmployeesFunctions/Index.cshtml create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/EmployeesRoles/Index.cshtml create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Personalization/Index.cshtml create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Shared/_Layout.cshtml create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Shared/_SoftwareSidebar.cshtml rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Views/Software/Index.cshtml (54%) rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Views/Software/SoftwareFunctions.cshtml (90%) create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Software/SoftwareListGroup.cshtml rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Views/Software/SoftwareVersions.cshtml (78%) rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Views/Software/Users.cshtml (79%) rename LaaProductionWeb/LaaProductionWeb/Areas/{Administration => Personalization}/Views/Software/UsersFunctions.cshtml (86%) create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/SoftwareFunctions/Index.cshtml create mode 100644 LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/_ViewStart.cshtml create mode 100644 LaaProductionWeb/LaaProductionWeb/Controllers/API/Personalization/EmployeesController.cs rename LaaProductionWeb/LaaProductionWeb/Controllers/API/{Account => Personalization}/LoginController.cs (82%) create mode 100644 LaaProductionWeb/LaaProductionWeb/Controllers/API/Personalization/RolesController.cs diff --git a/LaaProductionWeb/LaaProduction.Administration/Models/Employee.cs b/LaaProductionWeb/LaaProduction.Administration/Models/Employee.cs deleted file mode 100644 index 25779e39..00000000 --- a/LaaProductionWeb/LaaProduction.Administration/Models/Employee.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace LaaProduction.Administration.Models -{ - internal class Employee - { - public short EmployeeId { get; set; } - - public string DisplayName { get; set; } - - public string Username { get; set; } - } -} diff --git a/LaaProductionWeb/LaaProduction.Administration/Repositories/EmployeesRepository.cs b/LaaProductionWeb/LaaProduction.Administration/Repositories/EmployeesRepository.cs deleted file mode 100644 index f574ef53..00000000 --- a/LaaProductionWeb/LaaProduction.Administration/Repositories/EmployeesRepository.cs +++ /dev/null @@ -1,89 +0,0 @@ -namespace LaaProduction.Administration.Repositories -{ - using LaaProduction.Administration.Models; - using LaaProduction.Administration.Repositories.Interfaces; - - using LaaProductionSQL.Interfaces; - - using System.Collections.Generic; - - internal class EmployeesRepository : IEmployeesRepository - { - private readonly ISQLConnection sqlConnection; - - public EmployeesRepository(ISQLConnection sqlConnection) - => this.sqlConnection = sqlConnection; - - public void CreateToken(short appId, short userId) - => this.sqlConnection - .CreateCommand($@" - INSERT INTO [MitarbeiterTokens] ( - [AppId] - , [UserId]) - VALUES (@{nameof(appId)} - , @{nameof(userId)})") - .SetParameter(nameof(appId), appId) - .SetParameter(nameof(userId), userId) - .ExecuteNonQuery(); - - public short EmployeeId(string username, string password) - => this.sqlConnection - .CreateCommand($@" - SELECT [MitarbeiterNr] - FROM [Mitarbeiter] - WHERE [Benutzername] = @{nameof(username)} - AND [PasswordHash] = @{nameof(password)}") - .SetParameter(nameof(username), username) - .SetParameter(nameof(password), password) - .FirstOrDefault(x => x.GetSmallint()); - - public Employee GetEmployee(string token) - => this.sqlConnection - .CreateCommand($@" - SELECT [M].[MitarbeiterNr] - , [M].[Vorname] + ' ' + [M].[Name] - , [M].[Benutzername] - FROM [MitarbeiterTokens] AS [MT] - JOIN [Mitarbeiter] AS [M] - ON [M].[MitarbeiterNr] = [MT].[UserId] - WHERE [MT].[Token] = @{nameof(token)}") - .SetParameter(nameof(token), token) - .FirstOrDefault(x => new Employee - { - EmployeeId = x.GetSmallint(), - DisplayName = x.GetString(), - Username = x.GetString() - }); - - public string GetToken(short appId, short userId) - => this.sqlConnection - .CreateCommand($@" - SELECT [Token] - FROM [MitarbeiterTokens] - WHERE [AppId] = @{nameof(appId)} - AND [UserId] = @{nameof(userId)}") - .SetParameter(nameof(appId), appId) - .SetParameter(nameof(userId), userId) - .FirstOrDefault(x => x.GetString()); - - public IEnumerable GetUserRoles(string token) - => this.sqlConnection - .CreateCommand($@" - SELECT [MR].[Recht] - FROM [MitarbeiterTokens] AS [MT] - JOIN [MitarbeiterRechte] AS [MR] - ON [MR].[MitarbeiterNr] = [MT].[UserId] - WHERE [MT].[Token] = @{nameof(token)}") - .SetParameter(nameof(token), token) - .ExecuteReader(x => x.GetString()); - - public bool TokenExists(string token) - => this.sqlConnection - .CreateCommand($@" - SELECT COUNT(1) - FROM [MitarbeiterTokens] - WHERE [Token] = @{nameof(token)}") - .SetParameter(nameof(token), token) - .FirstOrDefault(x => x.GetInt() > 0); - } -} diff --git a/LaaProductionWeb/LaaProduction.Administration/AccountManagement.cs b/LaaProductionWeb/LaaProduction.Personalization/AccountManager.cs similarity index 82% rename from LaaProductionWeb/LaaProduction.Administration/AccountManagement.cs rename to LaaProductionWeb/LaaProduction.Personalization/AccountManager.cs index e44c3ade..0566ced1 100644 --- a/LaaProductionWeb/LaaProduction.Administration/AccountManagement.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/AccountManager.cs @@ -1,14 +1,14 @@ -namespace LaaProduction.Administration +namespace LaaProduction.Personalization { - using LaaProduction.Administration.Interfaces; - using LaaProduction.Administration.Repositories.Interfaces; + using LaaProduction.Personalization.Interfaces; + using LaaProduction.Personalization.Repositories.Interfaces; using System; using System.Collections.Generic; using System.Security.Claims; using System.Security.Principal; - public class AccountManagement : IAccountManagement + public class AccountManager : IAccountManager { private static IIdentity anonymous => new ClaimsIdentity( @@ -20,7 +20,7 @@ private readonly IEmployeesRepository employeesRepository; private readonly ISoftwareRepository softwareRepository; - public AccountManagement() + public AccountManager() { this.employeesRepository = ServiceProvider.GetService(); this.softwareRepository = ServiceProvider.GetService(); @@ -56,17 +56,18 @@ var claims = new List { new Claim(nameof(employee.EmployeeId), employee.EmployeeId.ToString()), - new Claim(nameof(employee.DisplayName), employee.DisplayName), + new Claim(nameof(employee.FullName), employee.FullName), new Claim(nameof(employee.Username), employee.Username), + new Claim(ClaimTypes.NameIdentifier, token), }; var userRoles = this.employeesRepository .GetUserRoles(token) - .Intersect(typeof(UserRoles)); + .Intersect(typeof(UsersRoles)); foreach (var role in userRoles) { - claims.Add(new Claim(nameof(UserRoles), role)); + claims.Add(new Claim(nameof(UsersRoles), role)); } var functions = this.softwareRepository @@ -82,7 +83,7 @@ claims: claims, authenticationType: nameof(ClaimsIdentity), nameType: nameof(employee.EmployeeId), - roleType: nameof(UserRoles)); + roleType: nameof(UsersRoles)); } return new ClaimsPrincipal(claimsIdentity); diff --git a/LaaProductionWeb/LaaProduction.Personalization/EmployeesManager.cs b/LaaProductionWeb/LaaProduction.Personalization/EmployeesManager.cs new file mode 100644 index 00000000..0bbfa0d4 --- /dev/null +++ b/LaaProductionWeb/LaaProduction.Personalization/EmployeesManager.cs @@ -0,0 +1,46 @@ +namespace LaaProduction.Personalization +{ + using LaaProduction.Personalization.Interfaces; + using LaaProduction.Personalization.Models; + using LaaProduction.Personalization.Repositories.Interfaces; + + using System; + using System.Collections.Generic; + using System.Linq; + + public class EmployeesManager : IEmployeesManager + { + private readonly IEmployeesRepository employeesRepository; + private readonly IRolesRepository rolesRepository; + + public EmployeesManager() + { + this.employeesRepository = ServiceProvider.GetService(); + this.rolesRepository = ServiceProvider.GetService(); + } + + public object GetEmployee(short employeeId) + => this.employeesRepository.Find(employeeId) + ?? new object { }; + + public IEnumerable GetEmployees() + => this.employeesRepository.All() + ?? Array.Empty(); + + public IEnumerable GetRoles() + => this.rolesRepository.All() + ?? Array.Empty(); + + public IDictionary GetRoles(short employeeId) + => this.rolesRepository + .All(employeeId) + .ToDictionary(x => x.Key, x => x.Value) + ?? new Dictionary(); + + public void UpdateEmployeeRoles(short employeeId, IEnumerable roles) + { + this.rolesRepository.Delete(employeeId); + this.rolesRepository.Insert(employeeId, roles); + } + } +} diff --git a/LaaProductionWeb/LaaProduction.Administration/Interfaces/IAccountManagement.cs b/LaaProductionWeb/LaaProduction.Personalization/Interfaces/IAccountManager.cs similarity index 66% rename from LaaProductionWeb/LaaProduction.Administration/Interfaces/IAccountManagement.cs rename to LaaProductionWeb/LaaProduction.Personalization/Interfaces/IAccountManager.cs index 4766558c..8996e061 100644 --- a/LaaProductionWeb/LaaProduction.Administration/Interfaces/IAccountManagement.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/Interfaces/IAccountManager.cs @@ -1,8 +1,8 @@ -namespace LaaProduction.Administration.Interfaces +namespace LaaProduction.Personalization.Interfaces { using System.Security.Principal; - public interface IAccountManagement + public interface IAccountManager { string GetAuthToken(string username, string password, string software); diff --git a/LaaProductionWeb/LaaProduction.Personalization/Interfaces/IEmployeesManager.cs b/LaaProductionWeb/LaaProduction.Personalization/Interfaces/IEmployeesManager.cs new file mode 100644 index 00000000..a5d864f8 --- /dev/null +++ b/LaaProductionWeb/LaaProduction.Personalization/Interfaces/IEmployeesManager.cs @@ -0,0 +1,17 @@ +namespace LaaProduction.Personalization.Interfaces +{ + using System.Collections.Generic; + + public interface IEmployeesManager + { + object GetEmployee(short employeeId); + + IEnumerable GetEmployees(); + + IDictionary GetRoles(short employeeId); + + IEnumerable GetRoles(); + + void UpdateEmployeeRoles(short employeeId, IEnumerable roles); + } +} diff --git a/LaaProductionWeb/LaaProduction.Administration/LaaProduction.Administration.csproj b/LaaProductionWeb/LaaProduction.Personalization/LaaProduction.Personalization.csproj similarity index 89% rename from LaaProductionWeb/LaaProduction.Administration/LaaProduction.Administration.csproj rename to LaaProductionWeb/LaaProduction.Personalization/LaaProduction.Personalization.csproj index c00000e0..c35e575e 100644 --- a/LaaProductionWeb/LaaProduction.Administration/LaaProduction.Administration.csproj +++ b/LaaProductionWeb/LaaProduction.Personalization/LaaProduction.Personalization.csproj @@ -7,8 +7,8 @@ {4C17FD42-7002-431A-8D6E-C57DD7D7C2D2} Library Properties - Administration - Administration + LaaProduction.Personalization + LaaProduction.Personalization v4.8.1 512 true @@ -60,18 +60,22 @@ - - - + + + + + + + - + diff --git a/LaaProductionWeb/LaaProduction.Personalization/Models/Employee.cs b/LaaProductionWeb/LaaProduction.Personalization/Models/Employee.cs new file mode 100644 index 00000000..f5ff01c0 --- /dev/null +++ b/LaaProductionWeb/LaaProduction.Personalization/Models/Employee.cs @@ -0,0 +1,15 @@ +namespace LaaProduction.Personalization.Models +{ + internal class Employee + { + public short EmployeeId { get; set; } + + public string FullName { get; set; } + + public string Username { get; set; } + + public int RolesCount { get; set; } + + public int FunctionsCount { get; set; } + } +} diff --git a/LaaProductionWeb/LaaProduction.Administration/Extensions.cs b/LaaProductionWeb/LaaProduction.Personalization/PersonalizationExtensions.cs similarity index 63% rename from LaaProductionWeb/LaaProduction.Administration/Extensions.cs rename to LaaProductionWeb/LaaProduction.Personalization/PersonalizationExtensions.cs index 624f0615..028cea05 100644 --- a/LaaProductionWeb/LaaProduction.Administration/Extensions.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/PersonalizationExtensions.cs @@ -1,6 +1,6 @@ -namespace LaaProduction.Administration +namespace LaaProduction.Personalization { - using LaaProduction.Administration.Interfaces; + using LaaProduction.Personalization.Interfaces; using Microsoft.Extensions.DependencyInjection; @@ -8,13 +8,15 @@ using System.Collections.Generic; using System.Linq; - public static class Extensions + public static class PersonalizationExtensions { public static IServiceCollection AddAdministration(this IServiceCollection services, string sqlConnectionString) { ServiceProvider.RegisterServices(sqlConnectionString); - return services.AddScoped(); + return services + .AddScoped() + .AddScoped(); } internal static IEnumerable Intersect(this IEnumerable source, Type enumType) diff --git a/LaaProductionWeb/LaaProduction.Administration/Properties/AssemblyInfo.cs b/LaaProductionWeb/LaaProduction.Personalization/Properties/AssemblyInfo.cs similarity index 100% rename from LaaProductionWeb/LaaProduction.Administration/Properties/AssemblyInfo.cs rename to LaaProductionWeb/LaaProduction.Personalization/Properties/AssemblyInfo.cs diff --git a/LaaProductionWeb/LaaProduction.Administration/README.md b/LaaProductionWeb/LaaProduction.Personalization/README.md similarity index 78% rename from LaaProductionWeb/LaaProduction.Administration/README.md rename to LaaProductionWeb/LaaProduction.Personalization/README.md index d63cce9c..ad865c47 100644 --- a/LaaProductionWeb/LaaProduction.Administration/README.md +++ b/LaaProductionWeb/LaaProduction.Personalization/README.md @@ -3,6 +3,8 @@ [Auftrag].[dbo].[Mitarbeiter] [Auftrag].[dbo].[MitarbeiterRechte] [Auftrag].[dbo].[MitarbeiterTokens] +[Auftrag].[dbo].[MitarbeiterTokens] [Auftrag].[dbo].[SoftwareFunctions] [Auftrag].[dbo].[SoftwareFunctionsLog] +[Auftrag].[dbo].[UsersFunctions] [Auftrag].[dbo].[VersionSoftwareAccess] \ No newline at end of file diff --git a/LaaProductionWeb/LaaProduction.Personalization/Repositories/EmployeesRepository.cs b/LaaProductionWeb/LaaProduction.Personalization/Repositories/EmployeesRepository.cs new file mode 100644 index 00000000..7e3bc52a --- /dev/null +++ b/LaaProductionWeb/LaaProduction.Personalization/Repositories/EmployeesRepository.cs @@ -0,0 +1,155 @@ +namespace LaaProduction.Personalization.Repositories +{ + using LaaProduction.Personalization.Models; + using LaaProduction.Personalization.Repositories.Interfaces; + + using LaaProductionSQL.Interfaces; + + using System.Collections.Generic; + + internal class EmployeesRepository : IEmployeesRepository + { + private readonly ISQLConnection sqlConnection; + + public EmployeesRepository(ISQLConnection sqlConnection) + => this.sqlConnection = sqlConnection; + + public IEnumerable 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]") + .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) + => this.sqlConnection + .CreateCommand($@" + INSERT INTO [MitarbeiterTokens] ( + [AppId] + , [UserId]) + VALUES (@{nameof(appId)} + , @{nameof(userId)})") + .SetParameter(nameof(appId), appId) + .SetParameter(nameof(userId), userId) + .ExecuteNonQuery(); + + public short EmployeeId(string username, string password) + => this.sqlConnection + .CreateCommand($@" + SELECT [MitarbeiterNr] + FROM [Mitarbeiter] + WHERE [Benutzername] = @{nameof(username)} + AND [PasswordHash] = @{nameof(password)}") + .SetParameter(nameof(username), username) + .SetParameter(nameof(password), password) + .FirstOrDefault(x => x.GetSmallint()); + + 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]") + .SetParameter(nameof(employeeId), employeeId) + .FirstOrDefault(x => new Employee + { + EmployeeId = x.GetSmallint(), + FullName = x.GetString(), + Username = x.GetString(), + RolesCount = x.GetInt(), + FunctionsCount = x.GetInt() + }); + + public Employee GetEmployee(string token) + => this.sqlConnection + .CreateCommand($@" + SELECT [M].[MitarbeiterNr] + , [M].[Vorname] + ' ' + [M].[Name] + , [M].[Benutzername] + FROM [MitarbeiterTokens] AS [MT] + JOIN [Mitarbeiter] AS [M] + ON [M].[MitarbeiterNr] = [MT].[UserId] + WHERE [MT].[Token] = @{nameof(token)}") + .SetParameter(nameof(token), token) + .FirstOrDefault(x => new Employee + { + EmployeeId = x.GetSmallint(), + FullName = x.GetString(), + Username = x.GetString() + }); + + public string GetToken(short appId, short userId) + => this.sqlConnection + .CreateCommand($@" + SELECT [Token] + FROM [MitarbeiterTokens] + WHERE [AppId] = @{nameof(appId)} + AND [UserId] = @{nameof(userId)}") + .SetParameter(nameof(appId), appId) + .SetParameter(nameof(userId), userId) + .FirstOrDefault(x => x.GetString()); + + public IEnumerable GetUserRoles(string token) + => this.sqlConnection + .CreateCommand($@" + SELECT [MR].[Recht] + FROM [MitarbeiterTokens] AS [MT] + JOIN [MitarbeiterRechte] AS [MR] + ON [MR].[MitarbeiterNr] = [MT].[UserId] + WHERE [MT].[Token] = @{nameof(token)}") + .SetParameter(nameof(token), token) + .ExecuteReader(x => x.GetString()); + + public bool TokenExists(string token) + => this.sqlConnection + .CreateCommand($@" + SELECT COUNT(1) + FROM [MitarbeiterTokens] + WHERE [Token] = @{nameof(token)}") + .SetParameter(nameof(token), token) + .FirstOrDefault(x => x.GetInt() > 0); + } +} diff --git a/LaaProductionWeb/LaaProduction.Administration/Repositories/Interfaces/IEmployeesRepository.cs b/LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/IEmployeesRepository.cs similarity index 67% rename from LaaProductionWeb/LaaProduction.Administration/Repositories/Interfaces/IEmployeesRepository.cs rename to LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/IEmployeesRepository.cs index dc0ede2a..9c7e704e 100644 --- a/LaaProductionWeb/LaaProduction.Administration/Repositories/Interfaces/IEmployeesRepository.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/IEmployeesRepository.cs @@ -1,15 +1,19 @@ -namespace LaaProduction.Administration.Repositories.Interfaces +namespace LaaProduction.Personalization.Repositories.Interfaces { - using LaaProduction.Administration.Models; + using LaaProduction.Personalization.Models; using System.Collections.Generic; internal interface IEmployeesRepository { + IEnumerable All(); + void CreateToken(short appId, short userId); short EmployeeId(string username, string password); + Employee Find(short employeeId); + Employee GetEmployee(string token); string GetToken(short appId, short userId); diff --git a/LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/IRolesRepository.cs b/LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/IRolesRepository.cs new file mode 100644 index 00000000..b5f7a7f9 --- /dev/null +++ b/LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/IRolesRepository.cs @@ -0,0 +1,15 @@ +namespace LaaProduction.Personalization.Repositories.Interfaces +{ + using System.Collections.Generic; + + public interface IRolesRepository + { + IEnumerable All(); + + IEnumerable> All(short employeeId); + + void Delete(short employeeId); + + void Insert(short employeeId, IEnumerable roles); + } +} diff --git a/LaaProductionWeb/LaaProduction.Administration/Repositories/Interfaces/ISoftwareRepository.cs b/LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/ISoftwareRepository.cs similarity index 75% rename from LaaProductionWeb/LaaProduction.Administration/Repositories/Interfaces/ISoftwareRepository.cs rename to LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/ISoftwareRepository.cs index ead3789f..f6ed0119 100644 --- a/LaaProductionWeb/LaaProduction.Administration/Repositories/Interfaces/ISoftwareRepository.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/ISoftwareRepository.cs @@ -1,4 +1,4 @@ -namespace LaaProduction.Administration.Repositories.Interfaces +namespace LaaProduction.Personalization.Repositories.Interfaces { using System.Collections.Generic; diff --git a/LaaProductionWeb/LaaProduction.Personalization/Repositories/RolesRepository.cs b/LaaProductionWeb/LaaProduction.Personalization/Repositories/RolesRepository.cs new file mode 100644 index 00000000..45a941d5 --- /dev/null +++ b/LaaProductionWeb/LaaProduction.Personalization/Repositories/RolesRepository.cs @@ -0,0 +1,52 @@ +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 All() + => this.sqlConnection + .CreateCommand(@" + SELECT DISTINCT [Recht] + FROM [MitarbeiterRechte]") + .ExecuteReader(x => x.GetString()); + + public IEnumerable> 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)}") + .SetParameter(nameof(employeeId), employeeId) + .ExecuteReader(x => new KeyValuePair(x.GetString(), x.GetBool())); + + 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 roles) + => this.sqlConnection + .CreateCommand($@" + INSERT INTO [MitarbeiterRechte] ([MitarbeiterNr], [Recht]) + VALUES {string.Join(", ", roles.Select((x, i) => $"('{employeeId}', '{new SqlParameter(i.ToString(), x).SqlValue}')"))}") + .ExecuteNonQuery(); + } +} diff --git a/LaaProductionWeb/LaaProduction.Administration/Repositories/SoftwareRepository.cs b/LaaProductionWeb/LaaProduction.Personalization/Repositories/SoftwareRepository.cs similarity index 91% rename from LaaProductionWeb/LaaProduction.Administration/Repositories/SoftwareRepository.cs rename to LaaProductionWeb/LaaProduction.Personalization/Repositories/SoftwareRepository.cs index e6c7896a..f80bbe05 100644 --- a/LaaProductionWeb/LaaProduction.Administration/Repositories/SoftwareRepository.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/Repositories/SoftwareRepository.cs @@ -1,6 +1,6 @@ -namespace LaaProduction.Administration.Repositories +namespace LaaProduction.Personalization.Repositories { - using LaaProduction.Administration.Repositories.Interfaces; + using LaaProduction.Personalization.Repositories.Interfaces; using LaaProductionSQL.Interfaces; diff --git a/LaaProductionWeb/LaaProduction.Administration/ServiceProvider.cs b/LaaProductionWeb/LaaProduction.Personalization/ServiceProvider.cs similarity index 76% rename from LaaProductionWeb/LaaProduction.Administration/ServiceProvider.cs rename to LaaProductionWeb/LaaProduction.Personalization/ServiceProvider.cs index b5bfa49f..d81de7ef 100644 --- a/LaaProductionWeb/LaaProduction.Administration/ServiceProvider.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/ServiceProvider.cs @@ -1,7 +1,7 @@ -namespace LaaProduction.Administration +namespace LaaProduction.Personalization { - using LaaProduction.Administration.Repositories; - using LaaProduction.Administration.Repositories.Interfaces; + using LaaProduction.Personalization.Repositories; + using LaaProduction.Personalization.Repositories.Interfaces; using LaaProductionSQL; @@ -21,6 +21,7 @@ serviceProvider = new ServiceCollection() .AddSingleton(_ => SQLConnection.CreateConnection(sqlConnectionString)) .AddScoped() + .AddScoped() .AddScoped() .BuildServiceProvider(); } diff --git a/LaaProductionWeb/LaaProduction.Administration/SoftwareFunctions.cs b/LaaProductionWeb/LaaProduction.Personalization/SoftwareFunctions.cs similarity index 93% rename from LaaProductionWeb/LaaProduction.Administration/SoftwareFunctions.cs rename to LaaProductionWeb/LaaProduction.Personalization/SoftwareFunctions.cs index a25e7e15..0b2a7458 100644 --- a/LaaProductionWeb/LaaProduction.Administration/SoftwareFunctions.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/SoftwareFunctions.cs @@ -1,4 +1,4 @@ -namespace LaaProduction.Administration +namespace LaaProduction.Personalization { public enum SoftwareFunctions { diff --git a/LaaProductionWeb/LaaProduction.Administration/UserRoles.cs b/LaaProductionWeb/LaaProduction.Personalization/UsersRoles.cs similarity index 95% rename from LaaProductionWeb/LaaProduction.Administration/UserRoles.cs rename to LaaProductionWeb/LaaProduction.Personalization/UsersRoles.cs index a3cd97b0..a031ea27 100644 --- a/LaaProductionWeb/LaaProduction.Administration/UserRoles.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/UsersRoles.cs @@ -1,6 +1,6 @@ -namespace LaaProduction.Administration +namespace LaaProduction.Personalization { - public enum UserRoles + public enum UsersRoles { AV_ABFRAGE_GEPRUEFTE, AV_ABFRAGEN6SIGMA, diff --git a/LaaProductionWeb/LaaProductionWeb.sln b/LaaProductionWeb/LaaProductionWeb.sln index 34576754..8f44ecaa 100644 --- a/LaaProductionWeb/LaaProductionWeb.sln +++ b/LaaProductionWeb/LaaProductionWeb.sln @@ -12,7 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documents", "Documents", "{ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProductionWeb", "LaaProductionWeb\LaaProductionWeb.csproj", "{D1AD077B-00E3-4663-AB9F-23FF65D98D2F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProduction.Administration", "LaaProduction.Administration\LaaProduction.Administration.csproj", "{4C17FD42-7002-431A-8D6E-C57DD7D7C2D2}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProduction.Personalization", "LaaProduction.Personalization\LaaProduction.Personalization.csproj", "{4C17FD42-7002-431A-8D6E-C57DD7D7C2D2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/LaaProductionWeb/LaaProductionWeb/App_Content/css/styles.css b/LaaProductionWeb/LaaProductionWeb/App_Content/css/styles.css index 7c877c4e..07a46480 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Content/css/styles.css +++ b/LaaProductionWeb/LaaProductionWeb/App_Content/css/styles.css @@ -174,3 +174,24 @@ span.td-error { color: var(--bs-danger); background-color: white; } + +.hover-dots { + position: relative; +} + +.hover-dots:hover::before { + content: "\F5D3"; + position: absolute; + top: .25rem; + right: 0; + display: inline-block; + font-family: bootstrap-icons !important; + font-style: normal; + font-weight: normal !important; + font-variant: normal; + text-transform: none; + line-height: 1; + vertical-align: -.125em; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} diff --git a/LaaProductionWeb/LaaProductionWeb/App_Content/js/scripts.js b/LaaProductionWeb/LaaProductionWeb/App_Content/js/scripts.js index 91533025..6f867aa5 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Content/js/scripts.js +++ b/LaaProductionWeb/LaaProductionWeb/App_Content/js/scripts.js @@ -3,7 +3,7 @@ document .querySelectorAll('.nav-link') .forEach(x => { - if (href.startsWith(x.href)) { + if (href == x.href) { x.classList.add('active'); } else { x.classList.remove('active'); diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AllowedRolesAttribute.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AllowedRolesAttribute.cs index 1ae87a06..b19c03fd 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AllowedRolesAttribute.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AllowedRolesAttribute.cs @@ -1,6 +1,6 @@ namespace LaaProductionWeb.App_Infrastructure { - using LaaProduction.Administration; + using LaaProduction.Personalization; using System.Web.Mvc; @@ -11,7 +11,7 @@ public AllowedRolesAttribute(params string[] roles) => this.Roles = string.Join(",", roles); - public AllowedRolesAttribute(params UserRoles[] roles) + public AllowedRolesAttribute(params UsersRoles[] roles) => this.Roles = string.Join(",", roles); protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizationFilter.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizationFilter.cs index 7d83ef1d..b0c488c0 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizationFilter.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizationFilter.cs @@ -1,6 +1,6 @@ namespace LaaProductionWeb.App_Infrastructure { - using LaaProduction.Administration.Interfaces; + using LaaProduction.Personalization.Interfaces; using IAuthorizationFilter = System.Web.Mvc.IAuthorizationFilter; using AuthorizationContext = System.Web.Mvc.AuthorizationContext; @@ -11,7 +11,7 @@ { var httpContext = filterContext.HttpContext; var sessionUser = httpContext.GetSessionUser(); - var accountManagement = ServiceProvider.Current.GetService(); + var accountManagement = ServiceProvider.GetService(); httpContext.User = accountManagement.GetClaimsPrincipal(sessionUser); if (httpContext.User.Identity.IsAuthenticated) diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizeBearerAttribute.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizeBearerAttribute.cs new file mode 100644 index 00000000..bfef8a9b --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizeBearerAttribute.cs @@ -0,0 +1,28 @@ +namespace LaaProductionWeb.App_Infrastructure +{ + using LaaProduction.Personalization.Interfaces; + + using System.Web.Http; + using System.Web.Http.Controllers; + + public class AuthorizeBearerAttribute : AuthorizeAttribute + { + private readonly IAccountManager accountManager; + + public AuthorizeBearerAttribute() + => this.accountManager = ServiceProvider.GetService(); + + protected override bool IsAuthorized(HttpActionContext actionContext) + { + if (actionContext.Request.Headers.Authorization?.Scheme == "Bearer") + { + var bearer = actionContext.Request.Headers.Authorization.Parameter; + var principal = this.accountManager.GetClaimsPrincipal(bearer); + + return principal.Identity.IsAuthenticated; + } + + return false; + } + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/HttpExtensions.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/HttpExtensions.cs index f84f2686..0e24ff9f 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/HttpExtensions.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/HttpExtensions.cs @@ -1,5 +1,6 @@ namespace LaaProductionWeb.App_Infrastructure { + using LaaProductionHttp.Interfaces; using Newtonsoft.Json; using System; @@ -10,6 +11,7 @@ using System.Security.Principal; using System.Text; using System.Web; + using System.Web.Mvc; /// /// Static class with extension methods that run on controller contexts. @@ -18,7 +20,7 @@ { const string ORDER_DATA = nameof(ORDER_DATA); const string URL_REFERER = nameof(URL_REFERER); - const string SESSION_USER = nameof(SESSION_USER); + const string LAA_USER = nameof(LAA_USER); public static TDST Map(this TSRC model, Func mapper) where TDST : class @@ -35,12 +37,24 @@ public static bool IsInRole(this IPrincipal principal, T role) => principal.IsInRole($"{role}"); - public static string DisplayName(this IPrincipal principal) + public static string GetNameIdentifier(this IPrincipal principal) { if (principal is ClaimsPrincipal claimsPrincipal) { return claimsPrincipal - .FindAll(nameof(DisplayName)) + .FindFirst(ClaimTypes.NameIdentifier) + ?.Value; + } + + return default(string); + } + + public static string FullName(this IPrincipal principal) + { + if (principal is ClaimsPrincipal claimsPrincipal) + { + return claimsPrincipal + .FindAll(nameof(FullName)) .LastOrDefault()?.Value; } @@ -64,7 +78,7 @@ .Request .Cookies .Get(URL_REFERER) - ?.Value ?? null; + ?.Value ?? "~/"; public static void SetUrlReferer(this HttpContextBase httpContext) => httpContext @@ -114,11 +128,11 @@ public static string GetSessionUser(this HttpContextBase httpContext) { var requestCookies = httpContext.Request.Cookies; - var sessionUser = requestCookies.Get(SESSION_USER); + var sessionUser = requestCookies.Get(LAA_USER); if (sessionUser is null) { - sessionUser = new HttpCookie(SESSION_USER, string.Empty); + sessionUser = new HttpCookie(LAA_USER, string.Empty); requestCookies.Add(sessionUser); } @@ -132,7 +146,7 @@ public static void SignIn(this HttpContextBase httpContext, string sessionUser) { httpContext.SignOut(); - httpContext.Response.AppendCookie(new HttpCookie(SESSION_USER, sessionUser) + httpContext.Response.AppendCookie(new HttpCookie(LAA_USER, sessionUser) { Expires = DateTime.Now.AddSeconds(Appsettings.LoginTimeout) }); @@ -140,8 +154,8 @@ public static void SignOut(this HttpContextBase httpContext) { - httpContext.Request.Cookies.Remove(SESSION_USER); - httpContext.Response.Cookies.Remove(SESSION_USER); + httpContext.Request.Cookies.Remove(LAA_USER); + httpContext.Response.Cookies.Remove(LAA_USER); } public static string ComputeHash(this string value) @@ -157,5 +171,24 @@ return value; } + + public static void AddModelErrors(this ModelStateDictionary modelState, IHttpErrorResponse response) + { + if (response != null) + { + if (response.Errors != null) + { + foreach (var error in response.Errors) + { + modelState.AddModelError(error.Key, error.Value); + } + } + + if (!string.IsNullOrWhiteSpace(response.Message)) + { + modelState.AddModelError(nameof(response.Message), response.Message); + } + } + } } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/RouteParameterAttribute.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/RouteParameterAttribute.cs new file mode 100644 index 00000000..df55f198 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/RouteParameterAttribute.cs @@ -0,0 +1,41 @@ +namespace LaaProductionWeb.App_Infrastructure +{ + using Newtonsoft.Json; + + using System.Linq; + using System.Web.Mvc; + + public class RouteParameterAttribute : ActionFilterAttribute + { + private readonly string parameterName; + + public RouteParameterAttribute(string parameterName) + => this.parameterName = parameterName; + + public override void OnActionExecuting(ActionExecutingContext filterContext) + { + base.OnActionExecuting(filterContext); + + if (filterContext.ActionParameters.ContainsKey(this.parameterName)) + { + var parameter = filterContext + .ActionDescriptor + .GetParameters() + .FirstOrDefault(); + var parameterValue = parameter.DefaultValue; + + try + { + var routeValue = filterContext + .RouteData + .GetRequiredString("id"); + + parameterValue = JsonConvert.DeserializeObject(routeValue, parameter.ParameterType); + } + catch { } + + filterContext.ActionParameters[this.parameterName] = parameterValue; + } + } + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/ServiceProvider.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/ServiceProvider.cs index fc54da8b..0dc951ad 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/ServiceProvider.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/ServiceProvider.cs @@ -1,6 +1,6 @@ namespace LaaProductionWeb { - using LaaProduction.Administration; + using LaaProduction.Personalization; using LaaProductionHttp; using LaaProductionSQL; @@ -16,7 +16,7 @@ { private static IServiceProvider serviceProvider; - public T GetService() where T : class + public static T GetService() where T : class => serviceProvider.GetService(); public static void RegisterServices() diff --git a/LaaProductionWeb/LaaProductionWeb/App_Start/RouteConfig.cs b/LaaProductionWeb/LaaProductionWeb/App_Start/RouteConfig.cs index 1e7010a5..9fb45a7a 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Start/RouteConfig.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Start/RouteConfig.cs @@ -9,6 +9,8 @@ { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); + routes.MapMvcAttributeRoutes(); + routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", diff --git a/LaaProductionWeb/LaaProductionWeb/App_Start/WebApiConfig.cs b/LaaProductionWeb/LaaProductionWeb/App_Start/WebApiConfig.cs index be33a243..01123a66 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Start/WebApiConfig.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Start/WebApiConfig.cs @@ -9,10 +9,15 @@ config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( - name: "AreasApi", - routeTemplate: "api/{area}/{controller}/{id}", + name: "PersonalizationApi", + routeTemplate: "api/Personalization/{controller}/{id}", defaults: new { id = RouteParameter.Optional }); + config.Routes.MapHttpRoute( + name: "PersonalizationActionApi", + routeTemplate: "api/Personalization/{controller}/{action}/{id}", + defaults: new { action = "Get", id = RouteParameter.Optional }); + config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/AdministrationAreaRegistration.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Administration/AdministrationAreaRegistration.cs deleted file mode 100644 index 3ab18347..00000000 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/AdministrationAreaRegistration.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace LaaProductionWeb.Areas.Administration -{ - using System.Web.Mvc; - - public class AdministrationAreaRegistration : AreaRegistration - { - public override string AreaName => "Administration"; - - public override void RegisterArea(AreaRegistrationContext context) - { - context.MapRoute( - name: "Administration_WithId", - url: "Administration/{controller}/{action}/{id}", - defaults: new { action = "Index", id = UrlParameter.Optional }); - } - } -} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Shared/_Layout.cshtml b/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Shared/_Layout.cshtml deleted file mode 100644 index dab76931..00000000 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Shared/_Layout.cshtml +++ /dev/null @@ -1,53 +0,0 @@ -@using LaaProductionWeb.App_Infrastructure - - - - - - - - - - @Styles.Render("~/bootstrap_css") - - - - @Styles.Render("~/styles_css") - - Laatzen Production Web - - - @if (this.User.IsInRole(UserRoles.WEB_Admin)) - { - - } - -
- @this.RenderBody() -
- - @Scripts.Render("~/bootstrap_js") - @Scripts.Render("~/barcodes_js") - @Scripts.Render("~/scripts_js") - @this.RenderSection("scripts", required: false) - - - diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Shared/_SoftwareSidebar.cshtml b/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Shared/_SoftwareSidebar.cshtml deleted file mode 100644 index 7d827ad0..00000000 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Shared/_SoftwareSidebar.cshtml +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Software/SoftwareListGroup.cshtml b/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Software/SoftwareListGroup.cshtml deleted file mode 100644 index 4d6f1656..00000000 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Software/SoftwareListGroup.cshtml +++ /dev/null @@ -1,13 +0,0 @@ -@model IEnumerable - -@if (this.Model?.Any() ?? false) -{ -
- @foreach (var software in this.Model) - { - - @software.Name - - } -
-} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/_ViewStart.cshtml b/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/_ViewStart.cshtml deleted file mode 100644 index 754ea95d..00000000 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/_ViewStart.cshtml +++ /dev/null @@ -1,3 +0,0 @@ -@{ - this.Layout = "~/Areas/Administration/Views/Shared/_Layout.cshtml"; -} diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/EmployeesController.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/EmployeesController.cs new file mode 100644 index 00000000..0fb1816e --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/EmployeesController.cs @@ -0,0 +1,91 @@ +namespace LaaProductionWeb.Areas.Personalization.Controllers +{ + using LaaProduction.Personalization; + using LaaProductionHttp.Interfaces; + using LaaProductionWeb.App_Infrastructure; + using LaaProductionWeb.Areas.Personalization.Models.Employees; + + using System; + using System.Collections.Generic; + using System.Threading.Tasks; + using System.Web.Mvc; + + [RouteArea("Personalization")] + [AllowedRoles(UsersRoles.WEB_Admin)] + public class EmployeesController : Controller + { + private readonly IHttpClient httpClient; + + public EmployeesController() + => this.httpClient = ServiceProvider.GetService(); + + [HttpGet] + public async Task Index() + { + var employeesResponse = await this.httpClient + .Get("/api/Personalization/Employees") + .AuthorizeBearer(this.User.GetNameIdentifier()) + .SendAsync>(); + var employeeysModel = new EmployeesListModel(); + + if (employeesResponse.Succeeded) + { + employeeysModel.Employees = employeesResponse.Value ?? Array.Empty(); + } + else + { + this.ModelState.AddModelErrors(employeesResponse); + } + + return this.View(employeeysModel); + } + + [HttpGet] + [RouteParameter("employeeId")] + public async Task Edit(short employeeId = 0) + { + var employeeResponse = await this.httpClient + .Get($"/api/Personalization/Employees/Find/{employeeId}") + .AuthorizeBearer(this.User.GetNameIdentifier()) + .SendAsync(); + var employeeEditModel = new EmployeeEditModel(); + + if (employeeResponse.Succeeded) + { + employeeEditModel = employeeResponse.Value; + + var rolesResponse = await this.httpClient + .Get($"/api/Personalization/Roles/Find/{employeeId}") + .AuthorizeBearer(this.User.GetNameIdentifier()) + .SendAsync>(); + + if (rolesResponse.Succeeded) + { + employeeEditModel.Roles = rolesResponse.Value ?? new Dictionary(); + } + else + { + this.ModelState.AddModelErrors(rolesResponse); + } + } + else + { + this.ModelState.AddModelErrors(employeeResponse); + } + + return this.View(employeeEditModel); + } + + [HttpPost] + public async Task EditRoles(EmployeeEditRolesModel model) + { + var result = await this.httpClient + .Post($"/api/Personalization/Employees/EditRoles") + .AuthorizeBearer(this.User.GetNameIdentifier()) + .WhitJsonBody(model) + .SendAsync(); + + return this.Redirect($"~/Personalization/Employees/Edit/{model.EmployeeId}"); + } + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/EmployeesFunctionsController.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/EmployeesFunctionsController.cs new file mode 100644 index 00000000..529bb6fa --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/EmployeesFunctionsController.cs @@ -0,0 +1,14 @@ +namespace LaaProductionWeb.Areas.Personalization.Controllers +{ + using System.Web.Mvc; + + [RouteArea("Personalization")] + public class EmployeesFunctionsController : Controller + { + [HttpGet] + public ActionResult Index() + { + return this.View(); + } + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/EmployeesRolesController.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/EmployeesRolesController.cs new file mode 100644 index 00000000..16fa3612 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/EmployeesRolesController.cs @@ -0,0 +1,14 @@ +namespace LaaProductionWeb.Areas.Personalization.Controllers +{ + using System.Web.Mvc; + + [RouteArea("Personalization")] + public class EmployeesRolesController : Controller + { + [HttpGet] + public ActionResult Index() + { + return this.View(); + } + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/PersonalizationController.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/PersonalizationController.cs new file mode 100644 index 00000000..0665db1e --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/PersonalizationController.cs @@ -0,0 +1,14 @@ +namespace LaaProductionWeb.Areas.Personalization.Controllers +{ + using System.Web.Mvc; + + [RouteArea("Presonalization")] + public class PersonalizationController : Controller + { + [HttpGet] + public ActionResult Index() + { + return this.View(); + } + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Controllers/SoftwareController.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/SoftwareController.cs similarity index 96% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Controllers/SoftwareController.cs rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/SoftwareController.cs index fc1a6428..d7251f71 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Controllers/SoftwareController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/SoftwareController.cs @@ -1,23 +1,23 @@ -namespace LaaProductionWeb.Areas.Administration.Controllers +namespace LaaProductionWeb.Areas.Personalization.Controllers { - using LaaProduction.Administration; + using LaaProduction.Personalization; using LaaProductionWeb.App_Infrastructure; - using LaaProductionWeb.Areas.Administration.Models.Software; + using LaaProductionWeb.Areas.Personalization.Models.Software; using LaaProductionWeb.Services.Interfaces; using System; using System.Linq; using System.Web.Mvc; - [RouteArea("Administration")] - [AllowedRoles(UserRoles.WEB_Admin)] + [RouteArea("Personalization")] + [AllowedRoles(UsersRoles.WEB_Admin)] public class SoftwareController : Controller { private readonly ISoftwareService softwareService; public SoftwareController() - => this.softwareService = ServiceProvider.Current.GetService(); + => this.softwareService = ServiceProvider.GetService(); [HttpGet] public ActionResult Index() diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/SoftwareFunctionsController.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/SoftwareFunctionsController.cs new file mode 100644 index 00000000..286fdf59 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/SoftwareFunctionsController.cs @@ -0,0 +1,14 @@ +namespace LaaProductionWeb.Areas.Personalization.Controllers +{ + using System.Web.Mvc; + + [RouteArea("Personalization")] + public class SoftwareFunctionsController : Controller + { + [HttpGet] + public ActionResult Index() + { + return this.View(); + } + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Employees/Employee.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Employees/Employee.cs new file mode 100644 index 00000000..01fff86a --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Employees/Employee.cs @@ -0,0 +1,15 @@ +namespace LaaProductionWeb.Areas.Personalization.Models.Employees +{ + public class Employee + { + public short EmployeeId { get; set; } + + public string FullName { get; set; } + + public string Username { get; set; } + + public int RolesCount { get; set; } + + public int FunctionsCount { get; set; } + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Employees/EmployeeEditModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Employees/EmployeeEditModel.cs new file mode 100644 index 00000000..3a715d7b --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Employees/EmployeeEditModel.cs @@ -0,0 +1,13 @@ +namespace LaaProductionWeb.Areas.Personalization.Models.Employees +{ + using System.Collections.Generic; + + public class EmployeeEditModel : Employee + { + public IDictionary Roles { get; set; } + = new Dictionary(); + + public IDictionary Functions { get; set; } + = new Dictionary(); + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Employees/EmployeeEditRolesModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Employees/EmployeeEditRolesModel.cs new file mode 100644 index 00000000..b741ed30 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Employees/EmployeeEditRolesModel.cs @@ -0,0 +1,14 @@ +namespace LaaProductionWeb.Areas.Personalization.Models.Employees +{ + using System; + using System.ComponentModel.DataAnnotations; + + public class EmployeeEditRolesModel + { + [Required] + public short? EmployeeId { get; set; } + + public string[] Roles { get; set; } + = Array.Empty(); + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Employees/EmployeesListModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Employees/EmployeesListModel.cs new file mode 100644 index 00000000..22a87aad --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Employees/EmployeesListModel.cs @@ -0,0 +1,11 @@ +namespace LaaProductionWeb.Areas.Personalization.Models.Employees +{ + using System; + using System.Collections.Generic; + + public class EmployeesListModel + { + public IEnumerable Employees { get; set; } + = Array.Empty(); + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/AddFunctionModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/AddFunctionModel.cs similarity index 79% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/AddFunctionModel.cs rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/AddFunctionModel.cs index af1da186..16c5fe21 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/AddFunctionModel.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/AddFunctionModel.cs @@ -1,4 +1,4 @@ -namespace LaaProductionWeb.Areas.Administration.Models.Software +namespace LaaProductionWeb.Areas.Personalization.Models.Software { using System.ComponentModel.DataAnnotations; diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/EditFunctionModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/EditFunctionModel.cs similarity index 82% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/EditFunctionModel.cs rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/EditFunctionModel.cs index f9fa331b..b87618a7 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/EditFunctionModel.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/EditFunctionModel.cs @@ -1,4 +1,4 @@ -namespace LaaProductionWeb.Areas.Administration.Models.Software +namespace LaaProductionWeb.Areas.Personalization.Models.Software { using System.ComponentModel.DataAnnotations; diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/FunctionUsersInputModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/FunctionUsersInputModel.cs similarity index 75% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/FunctionUsersInputModel.cs rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/FunctionUsersInputModel.cs index 9563d81f..1ef84e3d 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/FunctionUsersInputModel.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/FunctionUsersInputModel.cs @@ -1,4 +1,4 @@ -namespace LaaProductionWeb.Areas.Administration.Models.Software +namespace LaaProductionWeb.Areas.Personalization.Models.Software { using System.ComponentModel.DataAnnotations; diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareEditModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareEditModel.cs similarity index 73% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareEditModel.cs rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareEditModel.cs index d1c840e3..8e803b54 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareEditModel.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareEditModel.cs @@ -1,4 +1,4 @@ -namespace LaaProductionWeb.Areas.Administration.Models.Software +namespace LaaProductionWeb.Areas.Personalization.Models.Software { using System.Collections.Generic; diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareFunctionModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareFunctionModel.cs similarity index 72% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareFunctionModel.cs rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareFunctionModel.cs index 11808fa6..963bfb34 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareFunctionModel.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareFunctionModel.cs @@ -1,4 +1,4 @@ -namespace LaaProductionWeb.Areas.Administration.Models.Software +namespace LaaProductionWeb.Areas.Personalization.Models.Software { public class SoftwareFunctionModel { diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareFunctionsModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareFunctionsModel.cs similarity index 79% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareFunctionsModel.cs rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareFunctionsModel.cs index 5a93049b..82c9e00f 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareFunctionsModel.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareFunctionsModel.cs @@ -1,4 +1,4 @@ -namespace LaaProductionWeb.Areas.Administration.Models.Software +namespace LaaProductionWeb.Areas.Personalization.Models.Software { using System.Collections.Generic; diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareModel.cs similarity index 70% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareModel.cs rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareModel.cs index 70a24273..5631dc3a 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareModel.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareModel.cs @@ -1,4 +1,4 @@ -namespace LaaProductionWeb.Areas.Administration.Models.Software +namespace LaaProductionWeb.Areas.Personalization.Models.Software { using System.Collections.Generic; diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareOverviewModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareOverviewModel.cs similarity index 76% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareOverviewModel.cs rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareOverviewModel.cs index b812c948..3acc71b8 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareOverviewModel.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareOverviewModel.cs @@ -1,4 +1,4 @@ -namespace LaaProductionWeb.Areas.Administration.Models.Software +namespace LaaProductionWeb.Areas.Personalization.Models.Software { public class SoftwareOverviewModel { diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareUser.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareUser.cs similarity index 82% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareUser.cs rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareUser.cs index 6d804fa1..91fc404e 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareUser.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareUser.cs @@ -1,4 +1,4 @@ -namespace LaaProductionWeb.Areas.Administration.Models.Software +namespace LaaProductionWeb.Areas.Personalization.Models.Software { public class SoftwareUser { diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareVersionModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareVersionModel.cs similarity index 89% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareVersionModel.cs rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareVersionModel.cs index 463b55d0..7c368b21 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareVersionModel.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareVersionModel.cs @@ -1,4 +1,4 @@ -namespace LaaProductionWeb.Areas.Administration.Models.Software +namespace LaaProductionWeb.Areas.Personalization.Models.Software { using System; using System.Linq; diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareVersionsModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareVersionsModel.cs similarity index 74% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareVersionsModel.cs rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareVersionsModel.cs index 6195bdac..7a8217ee 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/SoftwareVersionsModel.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/SoftwareVersionsModel.cs @@ -1,4 +1,4 @@ -namespace LaaProductionWeb.Areas.Administration.Models.Software +namespace LaaProductionWeb.Areas.Personalization.Models.Software { using System.Collections.Generic; diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/UserFunctions.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/UserFunctions.cs similarity index 69% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/UserFunctions.cs rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/UserFunctions.cs index f99cb75d..1bbaba3f 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/UserFunctions.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/UserFunctions.cs @@ -1,4 +1,4 @@ -namespace LaaProductionWeb.Areas.Administration.Models.Software +namespace LaaProductionWeb.Areas.Personalization.Models.Software { using System.Collections.Generic; diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/UsersFunctionsInputModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/UsersFunctionsInputModel.cs similarity index 75% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/UsersFunctionsInputModel.cs rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/UsersFunctionsInputModel.cs index 77d3f3fe..929d4c13 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/UsersFunctionsInputModel.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/UsersFunctionsInputModel.cs @@ -1,4 +1,4 @@ -namespace LaaProductionWeb.Areas.Administration.Models.Software +namespace LaaProductionWeb.Areas.Personalization.Models.Software { using System.ComponentModel.DataAnnotations; diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/UsersFunctionsModel.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/UsersFunctionsModel.cs similarity index 83% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/UsersFunctionsModel.cs rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/UsersFunctionsModel.cs index 39e87b76..f311a292 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Models/Software/UsersFunctionsModel.cs +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Models/Software/UsersFunctionsModel.cs @@ -1,4 +1,4 @@ -namespace LaaProductionWeb.Areas.Administration.Models.Software +namespace LaaProductionWeb.Areas.Personalization.Models.Software { using System; using System.Collections.Generic; diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/PersonalizationAreaRegistration.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/PersonalizationAreaRegistration.cs new file mode 100644 index 00000000..e94ed6aa --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/PersonalizationAreaRegistration.cs @@ -0,0 +1,22 @@ +namespace LaaProductionWeb.Areas.Personalization +{ + using System.Web.Mvc; + + public class PersonalizationAreaRegistration : AreaRegistration + { + public override string AreaName => "Personalization"; + + public override void RegisterArea(AreaRegistrationContext context) + { + context.MapRoute( + name: "Personalization_WithId", + url: "Personalization/{controller}/{action}/{id}", + defaults: new { controller = "Personalization", action = "Index", id = UrlParameter.Optional }); + + context.MapRoute( + name: "Personalization_WithEmployeeId", + url: "Personalization/{controller}/{action}/{employeeId}", + defaults: new { controller = "Personalization", action = "Index", id = UrlParameter.Optional }); + } + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Employees/Edit.cshtml b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Employees/Edit.cshtml new file mode 100644 index 00000000..360e2098 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Employees/Edit.cshtml @@ -0,0 +1,86 @@ +@model EmployeeEditModel + +@using LaaProductionWeb.Areas.Personalization.Models.Employees + +
+
+
+

+ + + + @this.Model.FullName +

+ + + + + + + + + + + + + +
MitarbeiterNr:@this.Model.EmployeeId
Username:@this.Model.Username
Name:@this.Model.FullName
+
+
+ @this.Html.ValidationSummary() +
+
+
+ +
+
+
+ +
+
+ +
+
\ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Employees/Index.cshtml b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Employees/Index.cshtml new file mode 100644 index 00000000..2a197120 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Employees/Index.cshtml @@ -0,0 +1,79 @@ +@model EmployeesListModel + +@using LaaProductionWeb.Areas.Personalization.Models.Employees + +
+
+
+

Mitarbeiter

+
+
+ @this.Html.ValidationSummary() +
+ +
+
+
+ + + + + + + + + + + @foreach (var employee in this.Model.Employees) + { + + + + + + + } + +
MitarbeiternameBunutzernameAnzahl RechteAnzahl Funktionen
+ + @employee.FullName + + @employee.Username@employee.RolesCount@employee.FunctionsCount
+
+
+
+
+ +@section scripts { + +} diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/EmployeesFunctions/Index.cshtml b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/EmployeesFunctions/Index.cshtml new file mode 100644 index 00000000..4ec8ad0f --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/EmployeesFunctions/Index.cshtml @@ -0,0 +1,2 @@ +

Mitarbeiter Funktionen

+ diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/EmployeesRoles/Index.cshtml b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/EmployeesRoles/Index.cshtml new file mode 100644 index 00000000..5229e615 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/EmployeesRoles/Index.cshtml @@ -0,0 +1,2 @@ +

Mitarbeiter Rechte

+ diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Personalization/Index.cshtml b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Personalization/Index.cshtml new file mode 100644 index 00000000..9398d46e --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Personalization/Index.cshtml @@ -0,0 +1,3 @@ +
+

Personalisierung

+
\ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Shared/_Layout.cshtml b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Shared/_Layout.cshtml new file mode 100644 index 00000000..c5b0383e --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Shared/_Layout.cshtml @@ -0,0 +1,64 @@ +@using LaaProduction.Personalization +@using LaaProductionWeb.App_Infrastructure + + + + + + + + + + @Styles.Render("~/bootstrap_css") + + + + @Styles.Render("~/styles_css") + + Laatzen Production Web + + + + + +
+ @this.RenderBody() +
+ + @Scripts.Render("~/bootstrap_js") + @Scripts.Render("~/barcodes_js") + @Scripts.Render("~/scripts_js") + @this.RenderSection("scripts", required: false) + + + diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Shared/_SoftwareSidebar.cshtml b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Shared/_SoftwareSidebar.cshtml new file mode 100644 index 00000000..71ece3e2 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Shared/_SoftwareSidebar.cshtml @@ -0,0 +1,6 @@ + diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Software/Index.cshtml b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Software/Index.cshtml similarity index 54% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Software/Index.cshtml rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Software/Index.cshtml index 462bddeb..2874ac60 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Software/Index.cshtml +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Software/Index.cshtml @@ -1,13 +1,13 @@ -@model LaaProductionWeb.Areas.Administration.Models.Software.SoftwareModel +@model LaaProductionWeb.Areas.Personalization.Models.Software.SoftwareModel
@@ -28,8 +28,8 @@ @item.AppId @item.Name - @item.Versions - @item.Functions + @item.Versions + @item.Functions } diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Software/SoftwareFunctions.cshtml b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Software/SoftwareFunctions.cshtml similarity index 90% rename from LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Software/SoftwareFunctions.cshtml rename to LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Software/SoftwareFunctions.cshtml index e194019e..183caba8 100644 --- a/LaaProductionWeb/LaaProductionWeb/Areas/Administration/Views/Software/SoftwareFunctions.cshtml +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Views/Software/SoftwareFunctions.cshtml @@ -1,4 +1,4 @@ -@model LaaProductionWeb.Areas.Administration.Models.Software.SoftwareFunctionsModel +@model LaaProductionWeb.Areas.Personalization.Models.Software.SoftwareFunctionsModel @{ var softwareSelected = (this.Model?.AppId ?? 0) > 0; @@ -9,10 +9,10 @@
- Software + Software @if (softwareSelected) { - + Software Functions
@@ -40,7 +40,7 @@ } else { - + Software Functions
@@ -49,8 +49,8 @@ }
} - Users Functions - Users + Users Functions + Users
@@ -86,7 +86,7 @@ Users