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

139 lines
4.5 KiB
C#

namespace LaaProductionWeb.Areas.Personalization.Controllers
{
using LaaProduction.Personalization;
using LaaProductionWeb.App_Infrastructure;
using LaaProductionWeb.Areas.Personalization.Models.Software;
using LaaProductionDI;
using LaaProduction.Http.Interfaces;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web.Mvc;
[RouteArea("Personalization")]
[AllowedRoles(EmployeesRoles.WEB_Admin)]
public class SoftwareController : Controller
{
private readonly IHttpClient localHttp;
public SoftwareController()
=> this.localHttp = LaaServiceProvider.GetService<IHttpClient>();
[HttpGet]
public async Task<ActionResult> Index()
{
var softwareResult = await this.localHttp
.Get("/Personalization/Software/List")
.AuthorizeBearer(this.User.GetNameIdentifier())
.SendAsync<IEnumerable<SoftwareListItem>>();
if (!softwareResult.Succeeded)
{
this.ModelState.AddModelErrors(softwareResult);
}
return this.View(softwareResult.Value ?? Array.Empty<SoftwareListItem>());
}
[HttpGet]
public async Task<ActionResult> Details(int id)
{
var bearer = this.User.GetNameIdentifier();
var softwareResult = await this.localHttp
.Get($"/Personalization/Software/Version/{id}")
.AuthorizeBearer(bearer)
.SendAsync<SoftwareDetails>();
var softwareModel = new SoftwareDetails();
if (softwareResult.Succeeded)
{
softwareModel = softwareResult.Value ?? new SoftwareDetails();
var employeesResult = await this.localHttp
.Get($"/Personalization/Employees")
.AuthorizeBearer(bearer)
.SendAsync<IEnumerable<EmployeeShort>>();
if (employeesResult.Succeeded)
{
softwareModel.Employees = employeesResult.Value ?? Array.Empty<EmployeeShort>();
}
else
{
this.ModelState.AddModelErrors(softwareResult);
}
}
else
{
this.ModelState.AddModelErrors(softwareResult);
}
return this.View(softwareModel);
}
[HttpPost]
public async Task<ActionResult> EditFunction(FunctionEditModel model)
{
if (!this.ModelState.IsValid)
{
return this.Redirect("~/Personalization/Software");
}
await this.localHttp
.Post($"/Personalization/Software/EditFunction")
.AuthorizeBearer(this.User.GetNameIdentifier())
.WhitJsonBody(model)
.SendAsync<object>();
return this.Redirect($"~/Personalization/Software/Details/{model.VersionId}");
}
[HttpPost]
public async Task<ActionResult> AddVersion(SoftwareEditModel model)
{
if (!this.ModelState.IsValid)
{
return this.Redirect("~/Personalization/Software");
}
await this.localHttp
.Post($"/Personalization/Software/AddVersion")
.AuthorizeBearer(this.User.GetNameIdentifier())
.WhitJsonBody(model)
.SendAsync<object>();
return this.Redirect($"~/Personalization/Software/Details/{model.VersionId}");
}
[HttpPost]
public async Task<ActionResult> EditVersion(SoftwareEditModel model)
{
if (!this.ModelState.IsValid)
{
return this.Redirect("~/Personalization/Software");
}
await this.localHttp
.Post($"/Personalization/Software/EditVersion")
.AuthorizeBearer(this.User.GetNameIdentifier())
.WhitJsonBody(model)
.SendAsync<object>();
return this.Redirect($"~/Personalization/Software/Details/{model.VersionId}");
}
[HttpGet]
public async Task<ActionResult> DeleteVersion(int id)
{
await this.localHttp
.Get($"/Personalization/Software/DeleteVersion/{id}")
.AuthorizeBearer(this.User.GetNameIdentifier())
.SendAsync<object>();
return this.Redirect($"~/Personalization/Software");
}
}
}