laatzen/LaaProductionWeb/LaaProductionWeb/Areas/Personalization/Controllers/EmployeesRolesController.cs
Stoyan Zlatev dc4a3fa73a Register new AD user control
Change password control
2024-02-13 11:45:50 +01:00

73 lines
2.3 KiB
C#

namespace LaaProductionWeb.Areas.Personalization.Controllers
{
using LaaProductionWeb.App_Infrastructure;
using LaaProductionWeb.Areas.Personalization.Models.EmployeesRoles;
using LaaProductionDI;
using LaaProduction.Http.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 async Task<ActionResult> Index()
{
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_Shipment
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");
}
}
}