diff --git a/LaaProductionWeb/LaaProduction.Personalization/EmployeesManager.cs b/LaaProductionWeb/LaaProduction.Personalization/EmployeesManager.cs index a7df1621..c65ddfbf 100644 --- a/LaaProductionWeb/LaaProduction.Personalization/EmployeesManager.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/EmployeesManager.cs @@ -35,40 +35,9 @@ return employee ?? new object { }; } - public IEnumerable GetEmployees() - { - var employees = this.employeesRepository.All() ?? Array.Empty(); - - if (employees.Any()) - { - employees = employees.ToList(); - - var countFunctionsGroupedByEmployee = this.functionsRepository - .UserFunctionsCount() - .ToDictionary(x => x.Key, x => x.Value); - - var countRolesGroupedByEmployee = this.rolesRepository - .UsersRolesCount() - .ToDictionary(x => x.Key, x => x.Value); - - foreach (var employee in employees) - { - var employeeId = employee.EmployeeId; - - if (countRolesGroupedByEmployee.ContainsKey(employeeId)) - { - employee.RolesCount = countRolesGroupedByEmployee[employeeId]; - } - - if (countFunctionsGroupedByEmployee.ContainsKey(employeeId)) - { - employee.FunctionsCount = countFunctionsGroupedByEmployee[employeeId]; - } - } - } - - return employees; - } + public IEnumerable GetEmployees() + => this.employeesRepository.All() + ?? Array.Empty(); public IEnumerable GetRoles() => this.rolesRepository diff --git a/LaaProductionWeb/LaaProduction.Personalization/Interfaces/ISoftwareManager.cs b/LaaProductionWeb/LaaProduction.Personalization/Interfaces/ISoftwareManager.cs index 0846e7ff..a6deea9c 100644 --- a/LaaProductionWeb/LaaProduction.Personalization/Interfaces/ISoftwareManager.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/Interfaces/ISoftwareManager.cs @@ -1,13 +1,24 @@ namespace LaaProduction.Personalization.Interfaces { + using System; using System.Collections.Generic; public interface ISoftwareManager { + void AddVersion(short softwareId, string assemblyName, int majorV, int minorV, int buildV, DateTime validUntil, string description); + + void DeleteVersion(int versionId); + + void EditVersion(int versionId, DateTime? validUntil, string description); + IEnumerable GetFunctions(); IEnumerable GetFunctions(short appId); IEnumerable ListSoftwares(); + + object SoftwareDeteils(int versionId); + + void UpdateFunction(short softwareId, int functionId, string function, IEnumerable employees); } } diff --git a/LaaProductionWeb/LaaProduction.Personalization/LaaProduction.Personalization.csproj b/LaaProductionWeb/LaaProduction.Personalization/LaaProduction.Personalization.csproj index 214f8bb6..755cfda5 100644 --- a/LaaProductionWeb/LaaProduction.Personalization/LaaProduction.Personalization.csproj +++ b/LaaProductionWeb/LaaProduction.Personalization/LaaProduction.Personalization.csproj @@ -68,7 +68,10 @@ + + + @@ -91,7 +94,7 @@ - cd ..\..\ -LaaProduction.Personalization.Updater.exe + + \ No newline at end of file diff --git a/LaaProductionWeb/LaaProduction.Personalization/Models/Employee.cs b/LaaProductionWeb/LaaProduction.Personalization/Models/Employee.cs index 9f992320..b90bf64f 100644 --- a/LaaProductionWeb/LaaProduction.Personalization/Models/Employee.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/Models/Employee.cs @@ -20,4 +20,13 @@ public IEnumerable Functions { get; set; } } + + internal class EmployeeComparer : IEqualityComparer + { + public bool Equals(Employee x, Employee y) + => x?.EmployeeId == y?.EmployeeId; + + public int GetHashCode(Employee obj) + => obj?.EmployeeId ?? default(int); + } } diff --git a/LaaProductionWeb/LaaProduction.Personalization/Models/SoftwareDetails.cs b/LaaProductionWeb/LaaProduction.Personalization/Models/SoftwareDetails.cs new file mode 100644 index 00000000..0f5a45b8 --- /dev/null +++ b/LaaProductionWeb/LaaProduction.Personalization/Models/SoftwareDetails.cs @@ -0,0 +1,23 @@ +namespace LaaProduction.Personalization.Models +{ + using System.Collections.Generic; + + internal class SoftwareDetails + { + public short SoftwareId { get; set; } + + public int VersionId { get; set; } + + public string VersionNr { get; set; } + + public string ValidUntil { get; set; } + + public string AssemblyName { get; set; } + + public string Description { get; set; } + + public IEnumerable Versions { get; set; } + + public IEnumerable Functions { get; set; } + } +} diff --git a/LaaProductionWeb/LaaProduction.Personalization/Models/SoftwareFunction.cs b/LaaProductionWeb/LaaProduction.Personalization/Models/SoftwareFunction.cs new file mode 100644 index 00000000..0886b72c --- /dev/null +++ b/LaaProductionWeb/LaaProduction.Personalization/Models/SoftwareFunction.cs @@ -0,0 +1,11 @@ +namespace LaaProduction.Personalization.Models +{ + internal class SoftwareFunction + { + public short SoftwareId { get; set; } + + public int FunctionId { get; set; } + + public string Function { get; set; } + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProduction.Personalization/Models/SoftwareVersion.cs b/LaaProductionWeb/LaaProduction.Personalization/Models/SoftwareVersion.cs new file mode 100644 index 00000000..1cabd3ce --- /dev/null +++ b/LaaProductionWeb/LaaProduction.Personalization/Models/SoftwareVersion.cs @@ -0,0 +1,17 @@ +namespace LaaProduction.Personalization.Models +{ + internal class SoftwareVersion + { + public int VersionId { get; set; } + + public string VersionNr { get; set; } + + public string Description { get; set; } + + public string ValidUntil { get; set; } + + public short SoftwareId { get; set; } + + public string AssemblyName { get; set; } + } +} diff --git a/LaaProductionWeb/LaaProduction.Personalization/Repositories/EmployeesRepository.cs b/LaaProductionWeb/LaaProduction.Personalization/Repositories/EmployeesRepository.cs index 649b36f5..38a3fcf2 100644 --- a/LaaProductionWeb/LaaProduction.Personalization/Repositories/EmployeesRepository.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/Repositories/EmployeesRepository.cs @@ -6,6 +6,7 @@ using LaaProductionSQL.Interfaces; using System.Collections.Generic; + using System.Linq; internal class EmployeesRepository : IEmployeesRepository { @@ -18,17 +19,43 @@ => this.sqlConnection .CreateCommand($@" SELECT [M].[MitarbeiterNr] AS [EmployeeId] - , [M].[Vorname] + ' ' + [M].[Name] AS [FullName] - , [M].[Benutzername] AS [Username] + , [M].[Vorname] + ' ' + [M].[Name] AS [FullName] + , [M].[Benutzername] AS [Username] , [M].[PasswordHash] AS [Password] - FROM [Mitarbeiter] AS [M] + , [MR].[Recht] AS [Role] + , [SF].[Function] AS [Function] + FROM [Mitarbeiter] AS [M] + LEFT JOIN [MitarbeiterRechte] AS [MR] + ON [MR].[MitarbeiterNr] = [M].[MitarbeiterNr] + LEFT JOIN [UsersFunctions] AS [UF] + ON [UF].[UserId] = [M].[MitarbeiterNr] + LEFT JOIN [SoftwareFunctions] AS [SF] + ON [SF].[Id] = [UF].[SoftwareFunctionId] ORDER BY [FullName], [Username]") - .ExecuteReader(x => new Employee + .ExecuteReader(x => new { EmployeeId = x.GetSmallint(), FullName = x.GetString(), Username = x.GetString(), - HasPassword = !string.IsNullOrWhiteSpace(x.GetString()) + HasPassword = !string.IsNullOrWhiteSpace(x.GetString()), + Role = x.GetString(), + Function = x.GetString() + }) + .GroupBy(x => new Employee + { + EmployeeId = x.EmployeeId, + FullName = x.FullName, + Username = x.Username, + HasPassword = x.HasPassword, + }, new EmployeeComparer()) + .Select(x => + { + x.Key.Roles = x.Select(r => r.Role).Distinct(); + x.Key.RolesCount = x.Key.Roles.Count(); + x.Key.Functions = x.Select(f => f.Function).Distinct(); + x.Key.FunctionsCount = x.Key.Functions.Count(); + + return x.Key; }); public void CreateToken(short appId, short userId) diff --git a/LaaProductionWeb/LaaProduction.Personalization/Repositories/FunctionsRepository.cs b/LaaProductionWeb/LaaProduction.Personalization/Repositories/FunctionsRepository.cs index 3bb82843..0366b662 100644 --- a/LaaProductionWeb/LaaProduction.Personalization/Repositories/FunctionsRepository.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/Repositories/FunctionsRepository.cs @@ -4,6 +4,7 @@ using LaaProductionSQL.Interfaces; using System.Collections.Generic; + using System.Data.SqlClient; using System.Linq; internal class FunctionsRepository : IFunctionsRepository @@ -13,6 +14,24 @@ public FunctionsRepository(ISQLConnection sqlConnection) => this.sqlConnection = sqlConnection; + public void AddEmployeesFunctions(int functionId, IEnumerable employees) + => this.sqlConnection + .CreateCommand($@" + INSERT INTO [UsersFunctions] ([UserId], [SoftwareFunctionId]) + VALUES {string.Join(", ", employees.Select((x, i) => $"({new SqlParameter($"p{i}", x).SqlValue}, @{nameof(functionId)})"))}") + .SetParameter(nameof(functionId), functionId) + .ExecuteNonQuery(); + + public int AddFunction(short softwareId, string function) + => this.sqlConnection + .CreateCommand($@" + INSERT INTO [SoftwareFunctions] ([AppId], [Function]) + OUTPUT [inserted].[Id] + VALUES (@{nameof(softwareId)}, @{nameof(function)})") + .SetParameter(nameof(softwareId), softwareId) + .SetParameter(nameof(function), function) + .ExecuteScalar(x => x.GetInt()); + public IEnumerable All() => this.sqlConnection .CreateCommand($@" @@ -37,6 +56,24 @@ .SetParameter(nameof(employeeId), employeeId) .ExecuteNonQuery(); + public void DeleteEmployeesFunctions(int functionId) + => this.sqlConnection + .CreateCommand($@" + DELETE + FROM [UsersFunctions] + WHERE [SoftwareFunctionId] = @{nameof(functionId)}") + .SetParameter(nameof(functionId), functionId) + .ExecuteNonQuery(); + + public void DeleteFunction(int functionId) + => this.sqlConnection + .CreateCommand($@" + DELETE + FROM [SoftwareFunctions] + WHERE [Id] = @{nameof(functionId)}") + .SetParameter(nameof(functionId), functionId) + .ExecuteNonQuery(); + public IEnumerable EmployeeAll(short employeeId) => this.sqlConnection .CreateCommand($@" @@ -48,6 +85,17 @@ .SetParameter(nameof(employeeId), employeeId) .ExecuteReader(x => x.GetString()); + public bool Exists(int softwareId, int functionId) + => this.sqlConnection + .CreateCommand($@" + SELECT COUNT(1) + FROM [SoftwareFunctions] + WHERE [AppId] = @{nameof(softwareId)} + AND [Id] = @{nameof(functionId)}") + .SetParameter(nameof(softwareId), softwareId) + .SetParameter(nameof(functionId), functionId) + .FirstOrDefault(x => x.GetInt() > 0); + public void Insert(short employeeId, IEnumerable functions) => this.sqlConnection .CreateCommand($@" @@ -61,6 +109,16 @@ .SetParameter(nameof(employeeId), employeeId) .ExecuteNonQuery(); + public void UpdateFunction(int functionId, string function) + => this.sqlConnection + .CreateCommand($@" + UPDATE [SoftwareFunctions] + SET [Function] = @{nameof(function)} + WHERE [Id] = @{nameof(functionId)}") + .SetParameter(nameof(functionId), functionId) + .SetParameter(nameof(function), function) + .ExecuteNonQuery(); + public IEnumerable> UserFunctionsCount() => this.sqlConnection .CreateCommand($@" diff --git a/LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/IFunctionsRepository.cs b/LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/IFunctionsRepository.cs index ada06678..d9ff5c41 100644 --- a/LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/IFunctionsRepository.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/IFunctionsRepository.cs @@ -4,16 +4,28 @@ internal interface IFunctionsRepository { + void AddEmployeesFunctions(int functionId, IEnumerable employees); + + int AddFunction(short softwareId, string function); + IEnumerable All(); IEnumerable All(short appId); void Delete(short employeeId); + void DeleteEmployeesFunctions(int functionId); + + void DeleteFunction(int functionId); + IEnumerable EmployeeAll(short employeeId); + bool Exists(int softwareId, int functionId); + void Insert(short employeeId, IEnumerable functions); + void UpdateFunction(int functionId, string function); + IEnumerable> UserFunctionsCount(); } } diff --git a/LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/ISoftwareRepository.cs b/LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/ISoftwareRepository.cs index eb07be73..4304a2c0 100644 --- a/LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/ISoftwareRepository.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/Repositories/Interfaces/ISoftwareRepository.cs @@ -2,14 +2,27 @@ { using LaaProduction.Personalization.Models; + using System; using System.Collections.Generic; internal interface ISoftwareRepository { + void AddVersion(short softwareId, string assemblyName, int majorV, int minorV, int buildV, DateTime validUntil, string description); + short AppId(string software); + void Delete(int versionId); + + SoftwareDetails Details(int versionId); + + void EditVersion(int versionId, DateTime? validUntil, string description); + + IEnumerable Functions(short softwareId); + IEnumerable GetSoftwareFunctions(string token); IEnumerable List(); + + IEnumerable Versions(short softwareId); } } diff --git a/LaaProductionWeb/LaaProduction.Personalization/Repositories/SoftwareRepository.cs b/LaaProductionWeb/LaaProduction.Personalization/Repositories/SoftwareRepository.cs index 802f2c02..7201eabf 100644 --- a/LaaProductionWeb/LaaProduction.Personalization/Repositories/SoftwareRepository.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/Repositories/SoftwareRepository.cs @@ -4,6 +4,7 @@ using LaaProduction.Personalization.Repositories.Interfaces; using LaaProductionSQL.Interfaces; + using System; using System.Collections.Generic; internal class SoftwareRepository : ISoftwareRepository @@ -13,6 +14,33 @@ public SoftwareRepository(ISQLConnection sqlConnection) => this.sqlConnection = sqlConnection; + public void AddVersion(short softwareId, string assemblyName, int majorV, int minorV, int buildV, DateTime validUntil, string description) + => this.sqlConnection + .CreateCommand($@" + INSERT INTO [VersionSoftwareAccess] ( + [AppID] + , [SoftwareAccess_Program] + , [SoftwareAccess_MajorVersion] + , [SoftwareAccess_MinorVersion] + , [SoftwareAccess_BuildVersion] + , [SoftwareAccess_VaildTo] + , [SoftwareAccess_Desc]) + VALUES (@{nameof(softwareId)} + , @{nameof(assemblyName)} + , @{nameof(majorV)} + , @{nameof(minorV)} + , @{nameof(buildV)} + , @{nameof(validUntil)} + , @{nameof(description)})") + .SetParameter(nameof(softwareId), softwareId) + .SetParameter(nameof(assemblyName), assemblyName) + .SetParameter(nameof(majorV), majorV) + .SetParameter(nameof(minorV), minorV) + .SetParameter(nameof(buildV), buildV) + .SetParameter(nameof(validUntil), validUntil) + .SetParameter(nameof(description), description) + .ExecuteNonQuery(); + public short AppId(string software) => this.sqlConnection .CreateCommand($@" @@ -22,6 +50,66 @@ .SetParameter(nameof(software), software) .FirstOrDefault(x => x.GetSmallint()); + public void Delete(int versionId) + => this.sqlConnection + .CreateCommand($@" + DELETE FROM [VersionSoftwareAccess] + WHERE [SoftwareAccess_ID] = @{nameof(versionId)}") + .SetParameter(nameof(versionId), versionId) + .ExecuteNonQuery(); + + public SoftwareDetails Details(int versionId) + => this.sqlConnection + .CreateCommand($@" + SELECT [AppID] + , [SoftwareAccess_Program] + , [SoftwareAccess_MajorVersion] + , [SoftwareAccess_MinorVersion] + , [SoftwareAccess_BuildVersion] + , [SoftwareAccess_ID] + , [SoftwareAccess_VaildTo] + , [SoftwareAccess_Desc] + FROM [VersionSoftwareAccess] + WHERE [SoftwareAccess_ID] = @{nameof(versionId)}") + .SetParameter(nameof(versionId), versionId) + .FirstOrDefault(x => new SoftwareDetails + { + SoftwareId = x.GetSmallint(), + AssemblyName = x.GetString(), + VersionNr = $"{x.GetInt()}.{x.GetInt()}.{x.GetInt()}", + VersionId = x.GetInt(), + ValidUntil = $"{x.GetDate():yyyy-MM-dd}", + Description = x.GetString(), + }); + + public void EditVersion(int versionId, DateTime? validUntil, string description) + => this.sqlConnection + .CreateCommand($@" + UPDATE [VersionSoftwareAccess] + SET [SoftwareAccess_VaildTo] = @{nameof(validUntil)} + , [SoftwareAccess_Desc] = @{nameof(description)} + WHERE [SoftwareAccess_ID] = @{nameof(versionId)}") + .SetParameter(nameof(versionId), versionId) + .SetParameter(nameof(validUntil), validUntil) + .SetParameter(nameof(description), description) + .ExecuteNonQuery(); + + public IEnumerable Functions(short softwareId) + => this.sqlConnection + .CreateCommand($@" + SELECT [AppId] + , [Id] + , [Function] + FROM [SoftwareFunctions] + WHERE [AppId] = @{nameof(softwareId)}") + .SetParameter(nameof(softwareId), softwareId) + .ExecuteReader(x => new SoftwareFunction + { + SoftwareId = x.GetSmallint(), + FunctionId = x.GetInt(), + Function = x.GetString() + }); + public IEnumerable GetSoftwareFunctions(string token) => this.sqlConnection .CreateCommand($@" @@ -68,5 +156,29 @@ ValidUntil = $"{x.GetDate():yyyy-MM-dd}", Description = x.GetString(), }); + + public IEnumerable Versions(short softwareId) + => this.sqlConnection + .CreateCommand($@" + SELECT [AppId] + , [SoftwareAccess_Program] + , [SoftwareAccess_ID] + , [SoftwareAccess_MajorVersion] + , [SoftwareAccess_MinorVersion] + , [SoftwareAccess_BuildVersion] + , [SoftwareAccess_VaildTo] + , [SoftwareAccess_Desc] + FROM [VersionSoftwareAccess] + WHERE [AppId] = @{nameof(softwareId)}") + .SetParameter(nameof(softwareId), softwareId) + .ExecuteReader(x => new SoftwareVersion + { + SoftwareId = x.GetSmallint(), + AssemblyName = x.GetString(), + VersionId = x.GetInt(), + VersionNr = $"{x.GetInt()}.{x.GetInt()}.{x.GetInt()}", + ValidUntil = $"{x.GetDate():yyyy-MM-dd}", + Description = x.GetString(), + }); } } diff --git a/LaaProductionWeb/LaaProduction.Personalization/SoftwareManager.cs b/LaaProductionWeb/LaaProduction.Personalization/SoftwareManager.cs index 52b3c169..d2052d55 100644 --- a/LaaProductionWeb/LaaProduction.Personalization/SoftwareManager.cs +++ b/LaaProductionWeb/LaaProduction.Personalization/SoftwareManager.cs @@ -19,6 +19,15 @@ this.softwareRepository = LaaServiceProvider.GetService(); } + public void AddVersion(short softwareId, string assemblyName, int majorV, int minorV, int buildV, DateTime validUntil, string description) + => this.softwareRepository.AddVersion(softwareId, assemblyName, majorV, minorV, buildV, validUntil, description); + + public void DeleteVersion(int versionId) + => this.softwareRepository.Delete(versionId); + + public void EditVersion(int versionId, DateTime? validUntil, string description) + => this.softwareRepository.EditVersion(versionId, validUntil, description); + public IEnumerable GetFunctions() => this.functionsRepository.All() ?? Array.Empty(); @@ -30,5 +39,48 @@ public IEnumerable ListSoftwares() => this.softwareRepository.List() ?? Array.Empty(); + + public object SoftwareDeteils(int versionId) + { + var softwareDetails = this.softwareRepository.Details(versionId); + + if (softwareDetails != null) + { + softwareDetails.Versions = this.softwareRepository.Versions(softwareDetails.SoftwareId); + softwareDetails.Functions = this.softwareRepository.Functions(softwareDetails.SoftwareId); + } + + return softwareDetails; + } + + public void UpdateFunction(short softwareId, int functionId, string function, IEnumerable employees) + { + if (this.functionsRepository.Exists(softwareId, functionId)) + { + this.functionsRepository.DeleteEmployeesFunctions(functionId); + + if (string.IsNullOrWhiteSpace(function)) + { + this.functionsRepository.DeleteFunction(functionId); + } + else + { + this.functionsRepository.UpdateFunction(functionId, function); + this.functionsRepository.AddEmployeesFunctions(functionId, employees); + } + } + else + { + if (!string.IsNullOrWhiteSpace(function)) + { + functionId = this.functionsRepository.AddFunction(softwareId, function); + + if (functionId > 0) + { + this.functionsRepository.AddEmployeesFunctions(functionId, employees); + } + } + } + } } } diff --git a/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Controllers/EmployeesController.cs b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Controllers/EmployeesController.cs index 71b8d705..4ae07545 100644 --- a/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Controllers/EmployeesController.cs +++ b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Controllers/EmployeesController.cs @@ -44,6 +44,11 @@ return this.View(employeeysModel); } + public class JustRole + { + public string Name { get; set; } + } + [HttpGet] [RouteParameter("employeeId")] public async Task Edit(short employeeId = 0) @@ -71,11 +76,14 @@ var rolesResponse = await this.httpClient .Get($"/Personalization/Roles") .AuthorizeBearer(bearerToken) - .SendAsync>(); + .SendAsync>(); if (rolesResponse.Succeeded && rolesResponse.Value != null) { - var roles = rolesResponse.Value.ToDictionary(x => x, x => false); + var roles = rolesResponse + .Value + .Select(x => x.Name) + .ToDictionary(x => x, x => false); foreach (var role in employee.Roles) { diff --git a/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Controllers/SoftwareController.cs b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Controllers/SoftwareController.cs index ab73f504..a5dd6da7 100644 --- a/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Controllers/SoftwareController.cs +++ b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Controllers/SoftwareController.cs @@ -36,315 +36,104 @@ return this.View(softwareResult.Value ?? Array.Empty()); } - //private readonly ISoftwareService softwareService; + [HttpGet] + public async Task Details(int id) + { + var bearer = this.User.GetNameIdentifier(); - //public SoftwareController() - // => this.softwareService = LaaServiceProvider.GetService(); + var softwareResult = await this.localHttp + .Get($"/Personalization/Software/Version/{id}") + .AuthorizeBearer(bearer) + .SendAsync(); - //[HttpGet] - //public ActionResult Index() - //{ - // var model = new SoftwareModel - // { - // SoftwareInfo = this.softwareService - // .GetSoftwares() - // .Select(x => new SoftwareOverviewModel - // { - // AppId = x.AppId, - // Name = x.Name - // .Split('.') - // .LastOrDefault(), - // Versions = x.Versions, - // Functions = x.Functions - // }) - // }; + var softwareModel = new SoftwareDetails(); - // return this.View(model); - //} + if (softwareResult.Succeeded) + { + softwareModel = softwareResult.Value ?? new SoftwareDetails(); - //[HttpGet] - //public ActionResult SoftwareVersions(short? id) - //{ - // var model = new SoftwareVersionsModel(); + var employeesResult = await this.localHttp + .Get($"/Personalization/Employees") + .AuthorizeBearer(bearer) + .SendAsync>(); - // if (id.HasValue) - // { - // var appId = id.Value; + if (employeesResult.Succeeded) + { + softwareModel.Employees = employeesResult.Value ?? Array.Empty(); + } + else + { + this.ModelState.AddModelErrors(softwareResult); + } + } + else + { + this.ModelState.AddModelErrors(softwareResult); + } + + return this.View(softwareModel); + } - // model = this.softwareService - // .GetSoftwareOverview(appId) - // .Map(x => new SoftwareVersionsModel - // { - // AppId = x.AppId, - // Name = x.Name - // .Split('.') - // .LastOrDefault(), - // Versions = x.Versions, - // Functions = x.Functions - // }); + [HttpPost] + public async Task EditFunction(FunctionEditModel model) + { + if (!this.ModelState.IsValid) + { + return this.Redirect("~/Personalization/Software"); + } - // if (model != null) - // { - // model.SoftwareVersions = this.softwareService - // .GetSoftwareVersions(appId) - // .Select(x => new SoftwareVersionModel - // { - // AppId = x.AppId, - // BuildV = x.BuildV, - // Description = x.Description, - // FullName = x.FullName, - // Id = x.Id, - // MajorV = x.MajorV, - // MinorV = x.MinorV, - // ValidTo = x.ValidTo - // }); - // } - // } + await this.localHttp + .Post($"/Personalization/Software/EditFunction") + .AuthorizeBearer(this.User.GetNameIdentifier()) + .WhitJsonBody(model) + .SendAsync(); - // return this.View(model); - //} + return this.Redirect($"~/Personalization/Software/Details/{model.VersionId}"); + } - //[HttpGet] - //public ActionResult SoftwareFunctions(short? id) - //{ - // var appId = id ?? 0; - // var model = new SoftwareFunctionsModel(); + [HttpPost] + public async Task AddVersion(SoftwareEditModel model) + { + if (!this.ModelState.IsValid) + { + return this.Redirect("~/Personalization/Software"); + } - // if (appId > 0) - // { - // model = this.softwareService - // .GetSoftwareOverview(appId) - // .Map(x => new SoftwareFunctionsModel - // { - // AppId = x.AppId, - // Name = x.Name - // .Split('.') - // .LastOrDefault(), - // Versions = x.Versions, - // Functions = x.Functions - // }) ?? model; + await this.localHttp + .Post($"/Personalization/Software/AddVersion") + .AuthorizeBearer(this.User.GetNameIdentifier()) + .WhitJsonBody(model) + .SendAsync(); - // model.SoftwareFunctions = this.softwareService - // .GetSoftwareFunctions(appId) - // .Select(x => new SoftwareFunctionModel - // { - // Id = x.Id, - // AppId = x.AppId, - // Function = x.Function - // }); - // } - // else - // { - // model.SoftwareFunctions = this.softwareService - // .GetAllSoftwareFunctions() - // .Select(x => new SoftwareFunctionModel - // { - // Id = x.Id, - // AppId = x.AppId, - // Function = x.Function - // }); - // } + return this.Redirect($"~/Personalization/Software/Details/{model.VersionId}"); + } - // model.Users = this.softwareService - // .GetUsersWithFunctions() - // .Select(x => new UserFunctions - // { - // Id = x.Id, - // FirstName = x.FirstName, - // LastName = x.LastName, - // Username = x.Username, - // FunctionsCount = x.FunctionsCount, - // HasPassword = x.HasPassword, - // Functions = x.Functions - // ?.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries) - // ?.Select(f => int.TryParse(f, out int funcId) ? funcId : 0) - // ?.Where(f => f > 0) - // ?? Array.Empty() - // }); + [HttpPost] + public async Task EditVersion(SoftwareEditModel model) + { + if (!this.ModelState.IsValid) + { + return this.Redirect("~/Personalization/Software"); + } - // return this.View(model); - //} + await this.localHttp + .Post($"/Personalization/Software/EditVersion") + .AuthorizeBearer(this.User.GetNameIdentifier()) + .WhitJsonBody(model) + .SendAsync(); - //[HttpPost] - //public ActionResult SoftwareFunctions(FunctionUsersInputModel model) - //{ - // if (this.ModelState.IsValid) - // { - // this.softwareService.UpdateUsersFunctions(x => - // { - // x.FunctionId = model.FunctionId.Value; - // x.Users = model.Users; - // }); - // } + return this.Redirect($"~/Personalization/Software/Details/{model.VersionId}"); + } - // return this.Redirect(this.Request.UrlReferrer.ToString()); - //} + [HttpGet] + public async Task DeleteVersion(int id) + { + await this.localHttp + .Get($"/Personalization/Software/DeleteVersion/{id}") + .AuthorizeBearer(this.User.GetNameIdentifier()) + .SendAsync(); - //[HttpGet] - //public ActionResult SoftwareListGroup() - //{ - // var softwareList = this.softwareService - // .GetSoftwares() - // .Select(x => new SoftwareOverviewModel - // { - // AppId = x.AppId, - // Name = x.Name - // .Split('.') - // .LastOrDefault(), - // Versions = x.Versions, - // Functions = x.Functions - // }); - - // return this.PartialView(softwareList); - //} - - //[HttpPost] - //public string AddFunction(AddFunctionModel model) - //{ - // var appId = model.AppId.Value; - - // if (this.ModelState.IsValid) - // { - // this.softwareService.AddFunction(appId, model.Function); - // } - - // return this.ModelState - // .SelectMany(x => x.Value.Errors.Select(e => e.ErrorMessage)) - // .FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)); - //} - - //[HttpPost] - //public string EditFunction(EditFunctionModel model) - //{ - // if (this.ModelState.IsValid) - // { - // if (string.IsNullOrWhiteSpace(model.Function)) - // { - // this.softwareService.DeleteFunction(model.FuncId.Value); - // } - // else - // { - // this.softwareService.UpdateFunction(model.FuncId.Value, model.Function); - // } - // } - - // return this.ModelState - // .SelectMany(x => x.Value.Errors.Select(e => e.ErrorMessage)) - // .FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)); - //} - - //[HttpGet] - //public ActionResult Users() - //{ - // var usersModel = this.softwareService - // .GetUsers() - // .Select(x => new SoftwareUser - // { - // Id = x.Id, - // FirstName = x.FirstName, - // LastName = x.LastName, - // Username = x.Username, - // FunctionsCount = x.FunctionsCount, - // HasPassword = x.HasPassword - // }); - - // return this.View(usersModel); - //} - - //[HttpPost] - //public ActionResult Users(string username) - //{ - // var usersModel = this.softwareService - // .GetUsers(username) - // .Select(x => new SoftwareUser - // { - // Id = x.Id, - // FirstName = x.FirstName, - // LastName = x.LastName, - // Username = x.Username, - // FunctionsCount = x.FunctionsCount, - // HasPassword = x.HasPassword - // }); - - // return this.View(usersModel); - //} - - //[HttpGet] - //public ActionResult UpdatePWDS() - //{ - // this.softwareService.UpdatePasswordHashes(); - - // return this.RedirectToAction(nameof(Users)); - //} - - //[HttpPost] - //public bool ResetPWD(short id) - //{ - // this.softwareService.ResetPassword(id); - - // return true; - //} - - //[HttpGet] - //public ActionResult UsersFunctions(int? id, string username) - //{ - // object model; - - // if (id > 0) - // { - // model = this.UsersFunctionsModel(id: id.Value, username: $"{id}"); - // } - // else - // { - // model = this.UsersFunctionsModel(username: username); - // } - - // return this.View(model); - //} - - //[HttpPost] - //public ActionResult UsersFunctions(UsersFunctionsInputModel model) - //{ - // if (this.ModelState.IsValid) - // { - // this.softwareService.UpdateUsersFunctions(x => - // { - // x.UserId = model.UserId.Value; - // x.Functions = model.Functions; - // }); - // } - - // return this.Redirect(this.Request.UrlReferrer.ToString()); - //} - - //private UsersFunctionsModel UsersFunctionsModel(int id = -1, string username = null) - // => new UsersFunctionsModel - // { - // Functions = this.softwareService - // .GetAllSoftwareFunctions() - // .Select(x => new SoftwareFunctionModel - // { - // AppId = x.AppId, - // Function = x.Function, - // Id = x.Id, - // }), - // UsersFunctions = this.softwareService - // .GetUsersWithFunctions(id, username) - // .Select(x => new UserFunctions - // { - // Id = x.Id, - // FirstName = x.FirstName, - // LastName = x.LastName, - // Username = x.Username, - // FunctionsCount = x.FunctionsCount, - // HasPassword = x.HasPassword, - // Functions = x.Functions - // ?.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries) - // ?.Select(f => int.TryParse(f, out int funcId) ? funcId : 0) - // ?.Where(f => f > 0) - // ?? Array.Empty() - // }) - - // }; + return this.Redirect($"~/Personalization/Software"); + } } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Models/Software/FunctionEditModel.cs b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Models/Software/FunctionEditModel.cs new file mode 100644 index 00000000..6642d8a1 --- /dev/null +++ b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Models/Software/FunctionEditModel.cs @@ -0,0 +1,20 @@ +namespace LaaProduction.Web.Areas.Personalization.Models.Software +{ + using System.ComponentModel.DataAnnotations; + + public class FunctionEditModel + { + [Required] + public short? SoftwareId { get; set; } + + [Required] + public int? VersionId { get; set; } + + public int FunctionId { get; set; } + + [RegularExpression("[0-9a-z_A-Z]+")] + public string Function { get; set; } + + public short[] Employees { get; set; } + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Models/Software/SoftwareDetails.cs b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Models/Software/SoftwareDetails.cs new file mode 100644 index 00000000..d802e846 --- /dev/null +++ b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Models/Software/SoftwareDetails.cs @@ -0,0 +1,63 @@ +namespace LaaProduction.Web.Areas.Personalization.Models.Software +{ + using System; + using System.Collections.Generic; + + public class SoftwareDetails + { + public short SoftwareId { get; set; } + + public int VersionId { get; set; } + + public string VersionNr { get; set; } + + public string ValidUntil { get; set; } + + public string AssemblyName { get; set; } + + public string Description { get; set; } + + public IEnumerable Versions { get; set; } + = Array.Empty(); + + public IEnumerable Functions { get; set; } + = Array.Empty(); + + public IEnumerable Employees { get; set; } + = Array.Empty(); + } + + public class SoftwareVersion + { + public int VersionId { get; set; } + + public string VersionNr { get; set; } + + public string Description { get; set; } + + public string ValidUntil { get; set; } + + public short SoftwareId { get; set; } + + public string AssemblyName { get; set; } + } + + public class SoftwareFunction + { + public short SoftwareId { get; set; } + + public int FunctionId { get; set; } + + public string Function { get; set; } + } + + public class EmployeeShort + { + public short EmployeeId { get; set; } + + public string FullName { get; set; } + + public IEnumerable Functions { get; set; } + = Array.Empty(); + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Models/Software/SoftwareEditModel.cs b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Models/Software/SoftwareEditModel.cs new file mode 100644 index 00000000..171d66fb --- /dev/null +++ b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Models/Software/SoftwareEditModel.cs @@ -0,0 +1,46 @@ +namespace LaaProduction.Web.Areas.Personalization.Models.Software +{ + using System; + using System.ComponentModel.DataAnnotations; + using System.Linq; + + public class SoftwareEditModel + { + [Required] + public short? SoftwareId { get; set; } + + [Required] + public string AssemblyName { get; set; } + + public int? VersionId { get; set; } + + [Required] + [RegularExpression("\\d+\\.\\d+\\.\\d+")] + public string VersionNr + { + get => $"{this.MajorV}.{this.MinorV}.{this.BuildV}"; + set + { + var tokens = value + ?.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries) + ?.Select(x => int.TryParse($"{x}", out int t) ? t : 0) + ?? Array.Empty(); + + this.MajorV = tokens.FirstOrDefault(); + this.MinorV = tokens.Skip(1).FirstOrDefault(); + this.BuildV = tokens.Skip(2).FirstOrDefault(); + } + } + + public int MajorV { get; set; } + + public int MinorV { get; set; } + + public int BuildV { get; set; } + + [Required] + public DateTime? ValidUntil { get; set; } + + public string Description { get; set; } + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Models/_Software/SoftwareEditModel.cs b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Models/_Software/SoftwareEditModel.cs deleted file mode 100644 index f7136c51..00000000 --- a/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Models/_Software/SoftwareEditModel.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace LaaProduction.Web.Areas.Personalization.Models.Software -{ - using System.Collections.Generic; - - public class SoftwareEditModel : SoftwareVersionModel - { - public IEnumerable Functions { get; set; } - } -} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Models/_Software/SoftwareVersionModel.cs b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Models/_Software/SoftwareVersionModel.cs index 23852ac2..1885a8d1 100644 --- a/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Models/_Software/SoftwareVersionModel.cs +++ b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Models/_Software/SoftwareVersionModel.cs @@ -5,25 +5,5 @@ public class SoftwareVersionModel { - public int Id { get; set; } - - public short AppId { get; set; } - - public string Name - => this.FullName - ?.Split('.') - ?.LastOrDefault(); - - public string FullName { get; set; } - - public int MajorV { get; set; } - - public int MinorV { get; set; } - - public int BuildV { get; set; } - - public DateTime ValidTo { get; set; } - - public string Description { get; set; } } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Views/Employees/Edit.cshtml b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Views/Employees/Edit.cshtml index f759e8da..6edea606 100644 --- a/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Views/Employees/Edit.cshtml +++ b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Views/Employees/Edit.cshtml @@ -8,7 +8,7 @@

- + @this.Model.FullName diff --git a/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Views/Software/Details.cshtml b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Views/Software/Details.cshtml new file mode 100644 index 00000000..3d96a276 --- /dev/null +++ b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Views/Software/Details.cshtml @@ -0,0 +1,276 @@ +@model LaaProduction.Web.Areas.Personalization.Models.Software.SoftwareDetails + + +
+
+
+
+
+

+ + + + @this.Model.AssemblyName +

+ + + + + + + + + + + + + + + + + +
Software Id:@this.Model.SoftwareId
Version: + = 0 ? "text-bg-success" : "text-bg-secondary")"> + @this.Model.VersionNr + +
Gültig bis:@this.Model.ValidUntil
Beschreibung:@this.Model.Description
+
+
+
+
+ @this.Html.ValidationSummary() +
+
+
+
+
+

Funktionen

+ + + + + + + + + + + + + + @if (this.Model.Functions != null) + { + foreach (var function in this.Model.Functions) + { + var formId = $"func_{function.FunctionId}"; + var funcIn = $"{formId}_input"; + + + + + + + } + } + +
IdFunktionMitarbeiters
+ + + +
@function.FunctionId + + + +
+
+
+
+
+

Versionen

+ + + + + + + + + + + + + + + + + @if (this.Model.Versions != null) + { + foreach (var version in this.Model.Versions.OrderByDescending(x => x.ValidUntil)) + { + var formDate = $"version_date_{version.VersionId}"; + var formDesc = $"version_desc_{version.VersionId}"; + + + + + + + + } + } + +
Verion Id Version NrGültig bisBeschreibung
+
+ + + + + + + +
+
+ + + + + +
+
+ @version.VersionId + + + +
+
+ = 0 ? "text-bg-success" : "text-bg-secondary")"> + @version.VersionNr + + +
+ + + + + + +
+
+ +
+ + + + + + +
+
+
+
+
+ +@section scripts { + +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Views/Software/Index.cshtml b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Views/Software/Index.cshtml index a768f0f9..567135ed 100644 --- a/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Views/Software/Index.cshtml +++ b/LaaProductionWeb/LaaProduction.Web/Areas/Personalization/Views/Software/Index.cshtml @@ -24,10 +24,14 @@ @foreach (var software in this.Model) { - + @software.SoftwareId - @software.AssemblyName - @software.CurrentVersion + @software.AssemblyName + + = 0 ? "text-bg-success" : "text-bg-secondary")"> + @software.CurrentVersion + + @software.ValidUntil @software.Description @@ -37,43 +41,4 @@

- - -@*
-
- -
- @if (this.Model.SoftwareInfo != null) - { - - - - - - - - - - - @foreach (var item in this.Model.SoftwareInfo) - { - - - - - - - } - -
AppIdNameVersionsFunctions
@item.AppId@item.Name@item.Versions@item.Functions
- } -
-
-
*@ \ No newline at end of file + \ No newline at end of file diff --git a/LaaProductionWeb/LaaProduction.Web/Controllers/API/Personalization/SoftwareController.cs b/LaaProductionWeb/LaaProduction.Web/Controllers/API/Personalization/SoftwareController.cs index 325503be..f0cdfed9 100644 --- a/LaaProductionWeb/LaaProduction.Web/Controllers/API/Personalization/SoftwareController.cs +++ b/LaaProductionWeb/LaaProduction.Web/Controllers/API/Personalization/SoftwareController.cs @@ -4,6 +4,8 @@ using LaaProduction.Web.App_Infrastructure; using LaaProductionDI; + using System; + using System.ComponentModel.DataAnnotations; using System.Web.Http; [AuthorizeBearer] @@ -32,5 +34,118 @@ return this.Json(softwares); } + + [HttpGet] + [Route("Version/{id}")] + public IHttpActionResult Version(int id) + { + var software = this.softwareManager.SoftwareDeteils(id); + + return this.Json(software); + } + + [HttpPost] + [Route(nameof(EditFunction))] + public IHttpActionResult EditFunction([FromBody] EditFunctionModel model) + { + if (this.ModelState.IsValid) + { + this.softwareManager.UpdateFunction( + model.SoftwareId.Value, + model.FunctionId, + model.Function, + model.Employees); + } + + return this.Json(true); + } + + [HttpPost] + [Route(nameof(AddVersion))] + public IHttpActionResult AddVersion([FromBody] SoftwareAddModel model) + { + if (this.ModelState.IsValid) + { + this.softwareManager.AddVersion( + model.SoftwareId.Value, + model.AssemblyName, + model.MajorV, + model.MinorV, + model.BuildV, + model.ValidUntil.Value, + model.Description); + } + + return this.Json(true); + } + + [HttpPost] + [Route(nameof(EditVersion))] + public IHttpActionResult EditVersion([FromBody] SoftwareEditModel model) + { + if (this.ModelState.IsValid) + { + this.softwareManager.EditVersion( + model.VersionId.Value, + model.ValidUntil, + model.Description); + } + + return this.Json(true); + } + + [HttpGet] + [Route("DeleteVersion/{id}")] + public IHttpActionResult DeleteVersion(int id) + { + if (this.ModelState.IsValid) + { + this.softwareManager.DeleteVersion(id); + } + + return this.Json(true); + } + } + + public class EditFunctionModel + { + [Required] + public short? SoftwareId { get; set; } + + public int FunctionId { get; set; } + + public string Function { get; set; } + + public short[] Employees { get; set; } + } + + public class SoftwareAddModel + { + [Required] + public short? SoftwareId { get; set; } + + [Required] + public string AssemblyName { get; set; } + + public int MajorV { get; set; } + + public int MinorV { get; set; } + + public int BuildV { get; set; } + + [Required] + public DateTime? ValidUntil { get; set; } + + public string Description { get; set; } + } + + public class SoftwareEditModel + { + [Required] + public short? VersionId { get; set; } + + public DateTime? ValidUntil { get; set; } + + public string Description { get; set; } } } diff --git a/LaaProductionWeb/LaaProduction.Web/LaaProduction.Web.csproj b/LaaProductionWeb/LaaProduction.Web/LaaProduction.Web.csproj index d699bec7..e36b33e9 100644 --- a/LaaProductionWeb/LaaProduction.Web/LaaProduction.Web.csproj +++ b/LaaProductionWeb/LaaProduction.Web/LaaProduction.Web.csproj @@ -165,11 +165,13 @@ + + - + @@ -246,6 +248,7 @@ Designer +