Employees roles managing implemented

This commit is contained in:
Stoyan Zlatev
2023-06-21 14:42:09 +02:00
parent d041747fb4
commit 7919861bbf
26 changed files with 399 additions and 64 deletions
@@ -11,6 +11,8 @@
=> ConfigurationManager.AppSettings.Get(nameof(APIURL));
#endif
public static string APIPrefix => ConfigurationManager.AppSettings.Get(nameof(APIPrefix));
public static string ConnectionString => ConfigurationManager.AppSettings.Get(nameof(ConnectionString));
public static int LoginTimeout => int.TryParse(ConfigurationManager.AppSettings.Get(nameof(LoginTimeout)), out int time) ? time : 0;
@@ -25,7 +25,7 @@
public async Task<ActionResult> Index()
{
var employeesResponse = await this.httpClient
.Get("/api/Personalization/Employees")
.Get("/Personalization/Employees")
.AuthorizeBearer(this.User.GetNameIdentifier())
.SendAsync<IEnumerable<Employee>>();
var employeeysModel = new EmployeesListModel();
@@ -51,7 +51,7 @@
var bearerToken = this.User.GetNameIdentifier();
var employeeResponse = await this.httpClient
.Get($"/api/Personalization/Employees/Find/{employeeId}")
.Get($"Personalization/Employees/Find/{employeeId}")
.AuthorizeBearer(bearerToken)
.SendAsync<EmployeeFindModel>();
var employeeEditModel = new EmployeeEditModel();
@@ -69,7 +69,7 @@
});
var rolesResponse = await this.httpClient
.Get($"/api/Personalization/Roles")
.Get($"/Personalization/Roles")
.AuthorizeBearer(bearerToken)
.SendAsync<IEnumerable<string>>();
@@ -94,7 +94,7 @@
}
var funktionsResponse = await this.httpClient
.Get($"/api/Personalization/Software/Functions")
.Get($"/Personalization/Software/Functions")
.AuthorizeBearer(bearerToken)
.SendAsync<IEnumerable<string>>();
@@ -130,7 +130,7 @@
public async Task<ActionResult> EditRoles(EmployeeEditRolesModel model)
{
var result = await this.httpClient
.Post($"/api/Personalization/Employees/EditRoles")
.Post($"/Personalization/Employees/EditRoles")
.AuthorizeBearer(this.User.GetNameIdentifier())
.WhitJsonBody(model)
.SendAsync<object>();
@@ -142,7 +142,7 @@
public async Task<ActionResult> EditFunctions(EmployeeEditFunctionsModel model)
{
var result = await this.httpClient
.Post($"/api/Personalization/Employees/EditFunctions")
.Post($"/Personalization/Employees/EditFunctions")
.AuthorizeBearer(this.User.GetNameIdentifier())
.WhitJsonBody(model)
.SendAsync<object>();
@@ -154,7 +154,7 @@
public async Task<ActionResult> ResetPassword(short id)
{
var result = await this.httpClient
.Get($"/api/Personalization/Employees/ResetPassword/{id}")
.Get($"/Personalization/Employees/ResetPassword/{id}")
.AuthorizeBearer(this.User.GetNameIdentifier())
.SendAsync<object>();
@@ -167,7 +167,7 @@
if (this.ModelState.IsValid)
{
var result = await this.httpClient
.Post($"/api/Personalization/Employees/SetPassword")
.Post($"/Personalization/Employees/SetPassword")
.AuthorizeBearer(this.User.GetNameIdentifier())
.WhitJsonBody(new { model.EmployeeId, Password = model.PasswordI.ComputeHash() })
.SendAsync<object>();
@@ -1,14 +0,0 @@
namespace LaaProduction.Web.Areas.Personalization.Controllers
{
using System.Web.Mvc;
[RouteArea("Personalization")]
public class EmployeesFunctionsController : Controller
{
[HttpGet]
public ActionResult Index()
{
return this.View();
}
}
}
@@ -1,14 +1,73 @@
namespace LaaProduction.Web.Areas.Personalization.Controllers
{
using LaaProduction.Web.App_Infrastructure;
using LaaProduction.Web.Areas.Personalization.Models.EmployeesRoles;
using LaaProductionDI;
using LaaProductionHttp.Interfaces;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web.Mvc;
[RouteArea("Personalization")]
public class EmployeesRolesController : Controller
{
private readonly IHttpClient httpClient;
public EmployeesRolesController()
=> this.httpClient = LaaServiceProvider.GetService<IHttpClient>();
[HttpGet]
public ActionResult Index()
public async Task<ActionResult> Index()
{
return this.View();
var employeesRolesModel = new EmployeesRolesModel();
var rolesResult = await this.httpClient
.Get("/Personalization/Roles")
.AuthorizeBearer(this.User.GetNameIdentifier())
.SendAsync<IEnumerable<Role>>();
if (!rolesResult.Succeeded)
{
this.ModelState.AddModelErrors(rolesResult);
}
employeesRolesModel.Roles = rolesResult
.Value
?? Array.Empty<Role>();
var employeesResult = await this.httpClient
.Get("/Personalization/Employees/List")
.AuthorizeBearer(this.User.GetNameIdentifier())
.SendAsync<IEnumerable<Employee>>();
if (!employeesResult.Succeeded)
{
this.ModelState.AddModelErrors(employeesResult);
}
employeesRolesModel.Employees = employeesResult
.Value
?? Array.Empty<Employee>();
return this.View(employeesRolesModel);
}
[HttpPost]
public async Task<ActionResult> UpdateUsers(RoleUpdateModel model)
{
//WEB_PalettenScan
if (this.ModelState.IsValid)
{
var result = await this.httpClient
.Post("/Personalization/Roles/Update")
.AuthorizeBearer(this.User.GetNameIdentifier())
.WhitJsonBody(model)
.SendAsync<object>();
}
return this.Redirect("~/Personalization/EmployeesRoles");
}
}
}
@@ -0,0 +1,9 @@
namespace LaaProduction.Web.Areas.Personalization.Models.EmployeesRoles
{
public class Employee
{
public short EmployeeId { get; set; }
public string FullName { get; set; }
}
}
@@ -0,0 +1,11 @@
namespace LaaProduction.Web.Areas.Personalization.Models.EmployeesRoles
{
using System.Collections.Generic;
public class EmployeesRolesModel
{
public IEnumerable<Role> Roles { get; set; }
public IEnumerable<Employee> Employees { get; set; }
}
}
@@ -0,0 +1,11 @@
namespace LaaProduction.Web.Areas.Personalization.Models.EmployeesRoles
{
using System.Collections.Generic;
public class Role
{
public string Name { get; set; }
public IEnumerable<short> Employees { get; set; }
}
}
@@ -0,0 +1,12 @@
namespace LaaProduction.Web.Areas.Personalization.Models.EmployeesRoles
{
using System.ComponentModel.DataAnnotations;
public class RoleUpdateModel
{
[Required]
public string Role { get; set; }
public short[] Employees { get; set; }
}
}
@@ -4,10 +4,10 @@
<div class="container-fluid mt-3 mb-5">
<div class="row">
<div class="col-12 mb-5">
<div class="col-12 mb-3">
<h3>Mitarbeiter</h3>
<hr class="my-0" />
<div class="small text-danger mb-5">
<div class="small text-danger mb-3">
@this.Html.ValidationSummary()
</div>
<input id="employee_filter" type="search" class="form-control form-control-sm px-3 py-2" placeholder="Mitarbeiter filtern" />
@@ -1,2 +0,0 @@
<h2>Mitarbeiter Funktionen</h2>
@@ -1,2 +1,152 @@
<h2>Mitarbeiter Rechte</h2>
@model LaaProduction.Web.Areas.Personalization.Models.EmployeesRoles.EmployeesRolesModel
<div class="container-fluid mt-3 mb-5 h-100">
<div class="row h-100">
<div class="col-12 mb-3">
<h3>Mitarbeiter Rechte</h3>
<hr class="my-0" />
<div class="small text-danger mb-3">
@this.Html.ValidationSummary()
</div>
<input id="roles_filter" type="search" class="form-control form-control-sm px-3 py-2" placeholder="Rechte filtern" />
<p class="text-secondary my-3">
Beachten Sie, dass die Rechte nur in der Mitarbeiterrechtetabelle gespeichert werden.
Wird ein Recht für alle Mitarbeiter gelöscht, verschwindet es aus der Liste.
</p>
</div>
<div class="col-12 h-100">
<div class="table-responsive h-100">
<table class="table table-sm">
<thead>
<tr>
<th>Recht</th>
<th class="w-50">Mitarbaiter</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input class="form-control form-control-sm border-0 rounded-0"
placeholder="Neue Recht hinzufügen"
oninput="document.querySelector(`input[name='Role']`).value = this.value" />
</td>
<td class="w-50">
<div class="dropdown">
<button class="btn btn-sm btn-light rounded-0 dropdown-toggle w-100 text-start" type="button" data-bs-toggle="dropdown" aria-expanded="false">
</button>
<div class="dropdown-menu w-100 over">
<form action="~/Personalization/EmployeesRoles/UpdateUsers" method="post" id="add_role" class="p-3">
<input type="hidden" name="Role" />
<input class="form-control form-control-sm" oninput="filterEmployees(this)" />
<div class="scrollable-sm mt-3 px-1" style="max-height: 300px">
@foreach (var e in this.Model.Employees)
{
var id = $"add_role_{e.EmployeeId}";
<div class="form-check">
<input class="form-check-input" type="checkbox" value="@e.EmployeeId" name="Employees[]" id="@id" />
<label class="form-check-label">@e.FullName</label>
</div>
}
</div>
<button class="btn btn-light btn-sm w-100 border fw-bold mt-3" type="submit">Aktualizieren</button>
</form>
</div>
</div>
</td>
</tr>
@{
var roleCounter = 1;
}
@foreach (var role in this.Model.Roles)
{
var formId = $"form_{roleCounter++}";
<tr>
<td>@role.Name</td>
<td class="w-50">
<div class="dropdown">
<button class="btn btn-sm btn-light rounded-0 dropdown-toggle w-100 text-start" type="button" data-bs-toggle="dropdown" aria-expanded="false">
@role.Employees.Count()
</button>
<div class="dropdown-menu w-100 over">
<form action="~/Personalization/EmployeesRoles/UpdateUsers" method="post" id="@formId" class="p-3">
<input type="hidden" name="Role" value="@role.Name" />
<input class="form-control form-control-sm" oninput="filterEmployees(this)" />
<div class="scrollable-sm mt-3 px-1" style="max-height: 300px">
@foreach (var e in this.Model.Employees)
{
var id = $"{formId}_{e.EmployeeId}";
<div class="form-check">
<input class="form-check-input"
type="checkbox"
value="@e.EmployeeId"
name="Employees[]"
id="@id" @(role.Employees.Contains(e.EmployeeId) ? "checked=\"checked\"" : null)>
<label class="form-check-label">@e.FullName</label>
</div>
}
</div>
<button class="btn btn-light btn-sm w-100 border fw-bold mt-3" type="submit">Aktualizieren</button>
</form>
</div>
</div>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
</div>
@section scripts {
<script>
function filterEmployees(e) {
let filter = e.value;
let employees = e.nextElementSibling.children;
if (filter) {
filter = filter.toLowerCase();
Array
.from(employees)
.forEach(function (div) {
let value = div.querySelector('label').innerText.toLowerCase();
console.log(value);
if (value.includes(filter) || filter.includes(value)) {
div.classList.remove('d-none');
} else {
div.classList.add('d-none');
}
});
} else {
employees.classList.remove('d-none');
}
}
document
.getElementById('roles_filter')
.oninput = function (e) {
let filter = e.target.value.toLowerCase();
let trs = document.querySelectorAll('tbody > tr');
if (filter) {
trs.forEach(function (tr) {
let children = tr.children;
let text = tr.children[0].textContent.toLowerCase();
if (text.includes(filter) || filter.includes(text)) {
tr.classList.remove('d-none');
} else {
tr.classList.add('d-none');
}
});
} else {
trs.forEach(function (tr) {
tr.classList.remove('d-none');
});
}
};
</script>
}
@@ -1,8 +1,8 @@
@using LaaProduction.Personalization
@using LaaProduction.Web.App_Infrastructure
@using LaaProduction.Web.App_Infrastructure
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -17,6 +17,7 @@
<title>Laatzen Production Web</title>
</head>
<body class="d-flex flex-column vh-100 overflow-hidden">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark shadow-sm">
@@ -32,9 +33,6 @@
<li class="nav-item">
<a class="nav-link text-smallcaps" href="~/Personalization/EmployeesRoles">Mitarbeiter Rechte</a>
</li>
<li class="nav-item">
<a class="nav-link text-smallcaps" href="~/Personalization/EmployeesFunctions">Mitarbeiter Funktionen</a>
</li>
<li class="nav-item">
<a class="nav-link text-smallcaps" href="~/Personalization/SoftwareFunctions">Software Funktionen</a>
</li>
@@ -1,7 +1,5 @@
@model LaaProduction.Web.Areas.Personalization.Models.Software.UsersFunctionsModel
@using System.Linq
<div class="container-fluid h-100">
<div class="row h-100 overflow-hidden">
<div class="col-2 bg-light h-100">
@@ -84,6 +84,15 @@
return this.Json(true);
}
[HttpGet]
[Route(nameof(List))]
public IHttpActionResult List()
{
var employees = this.employeesManager.ListEmployees();
return this.Json(employees);
}
}
public class EditRolesModel
@@ -91,8 +100,7 @@
[Required]
public short? EmployeeId { get; set; }
public string[] Roles { get; set; }
= Array.Empty<string>();
public string[] Roles { get; set; } = Array.Empty<string>();
}
public class EditFunctionsModel
@@ -100,8 +108,7 @@
[Required]
public short? EmployeeId { get; set; }
public string[] Functions { get; set; }
= Array.Empty<string>();
public string[] Functions { get; set; } = Array.Empty<string>();
}
public class PasswordModel
@@ -4,9 +4,12 @@
using LaaProduction.Web.App_Infrastructure;
using LaaProductionDI;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web.Http;
[AuthorizeBearer]
[RoutePrefix("api/Personalization/Roles")]
public class RolesController : ApiController
{
private readonly IEmployeesManager employeesManager;
@@ -17,7 +20,9 @@
[HttpGet]
public IHttpActionResult Get()
{
var employeeRoles = this.employeesManager.GetRoles();
var employeeRoles = this.employeesManager
.GetRoles()
.ToList();
return this.Json(employeeRoles);
}
@@ -29,5 +34,25 @@
return this.Json(employeeRoles);
}
[HttpPost]
[Route(nameof(Update))]
public IHttpActionResult Update([FromBody] RoleUpdateModel model)
{
if (this.ModelState.IsValid)
{
this.employeesManager.UpdateRoleEmployees(model.Role, model.Employees);
}
return this.Json(true);
}
}
public class RoleUpdateModel
{
[Required]
public string Role { get; set; }
public short[] Employees { get; set; }
}
}
@@ -45,7 +45,7 @@
.Name;
var token = await this.httpClient
.Post("/LaaProductionWeb/api/Personalization/Login")
.Post("/Personalization/Login")
.WhitJsonBody(new { username, password, software })
.SendAsync<string>();
@@ -54,7 +54,7 @@
public async Task<ActionResult> Wildcard()
{
var fieldsResult = await this.httpClient
.Get("/LaaProductionWeb/api/Search/Wildcard")
.Get("/Search/Wildcard")
.AuthorizeBearer(this.User.GetNameIdentifier())
.SendAsync<IEnumerable<string>>();
@@ -87,7 +87,7 @@
}
var httpResult = await this.httpClient
.Post($"/LaaProductionWeb/api/Search/Wildcard")
.Post($"/Search/Wildcard")
.WhitJsonBody(new { model.Token, fields })
.AuthorizeBearer(this.User.GetNameIdentifier())
.SendAsync<IEnumerable<IDictionary<string, object>>>();
@@ -30,8 +30,8 @@
private void ConfigureServices(LaaServiceCollection services)
=> services
.AddSingleton(SQLConnection.CreateConnection(Appsettings.ConnectionString))
.AddSingleton(HttpClient.CreateHttpClient(Appsettings.APIURL))
.AddSingleton(SQLConnection.CreateSQLConnection(Appsettings.ConnectionString))
.AddSingleton(HttpClient.CreateHttpClient(Appsettings.APIURL, Appsettings.APIPrefix))
.AddScoped<IAccountService, AccountService>()
.AddScoped<IApprovalsService, ApprovalsService>()
.AddScoped<ILoggerService, LoggerService>()
@@ -152,11 +152,14 @@
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\WebApiConfig.cs" />
<Compile Include="Areas\Personalization\Controllers\EmployeesController.cs" />
<Compile Include="Areas\Personalization\Controllers\EmployeesFunctionsController.cs" />
<Compile Include="Areas\Personalization\Controllers\EmployeesRolesController.cs" />
<Compile Include="Areas\Personalization\Controllers\PersonalizationController.cs" />
<Compile Include="Areas\Personalization\Controllers\SoftwareController.cs" />
<Compile Include="Areas\Personalization\Controllers\SoftwareFunctionsController.cs" />
<Compile Include="Areas\Personalization\Models\EmployeesRoles\Employee.cs" />
<Compile Include="Areas\Personalization\Models\EmployeesRoles\EmployeesRolesModel.cs" />
<Compile Include="Areas\Personalization\Models\EmployeesRoles\Role.cs" />
<Compile Include="Areas\Personalization\Models\EmployeesRoles\RoleUpdateModel.cs" />
<Compile Include="Areas\Personalization\Models\Employees\Employee.cs" />
<Compile Include="Areas\Personalization\Models\Employees\EmployeeEditFunctionsModel.cs" />
<Compile Include="Areas\Personalization\Models\Employees\EmployeeEditModel.cs" />
@@ -232,7 +235,6 @@
<Content Include="Areas\Personalization\Views\_ViewStart.cshtml" />
<Content Include="Areas\Personalization\Views\Employees\Edit.cshtml" />
<Content Include="Areas\Personalization\Views\Employees\Index.cshtml" />
<Content Include="Areas\Personalization\Views\EmployeesFunctions\Index.cshtml" />
<Content Include="Areas\Personalization\Views\EmployeesRoles\Index.cshtml" />
<Content Include="Areas\Personalization\Views\Personalization\Index.cshtml" />
<Content Include="Areas\Personalization\Views\Shared\_Layout.cshtml" />