172 lines
4.8 KiB
C#
172 lines
4.8 KiB
C#
namespace LaaProduction.Web.Controllers
|
|
{
|
|
using LaaProduction.Personalization;
|
|
using LaaProduction.Personalization.Interfaces;
|
|
using LaaProduction.Personalization.Models;
|
|
using LaaProduction.Web.App_Infrastructure;
|
|
using LaaProductionDI;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
|
|
[AllowedRoles(EmployeesRoles.WEB_Equipments)]
|
|
public class EquipmentsController : Controller
|
|
{
|
|
private readonly IEquipmentsManager equipmentsManager;
|
|
private readonly ISoftwareManager softwareManager;
|
|
|
|
public EquipmentsController()
|
|
{
|
|
this.equipmentsManager = LaaServiceProvider.GetService<IEquipmentsManager>();
|
|
this.softwareManager = LaaServiceProvider.GetService<ISoftwareManager>();
|
|
}
|
|
|
|
[HttpGet]
|
|
public ActionResult Index(int id = 0)
|
|
{
|
|
var model = this.equipmentsManager.FindById(id);
|
|
|
|
return this.View(model);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult Add(PruefmittelPruefung model)
|
|
{
|
|
if (this.ModelState.IsValid)
|
|
{
|
|
var id = this.equipmentsManager.Add(model);
|
|
|
|
if (id > 0)
|
|
{
|
|
return this.RedirectToAction(nameof(Index), new { id });
|
|
}
|
|
}
|
|
|
|
return this.View(nameof(Index), model);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult Edit(PruefmittelPruefung model)
|
|
{
|
|
if (this.ModelState.IsValid)
|
|
{
|
|
var updated = this.equipmentsManager.Update(model);
|
|
}
|
|
|
|
return this.View(nameof(Index), model);
|
|
}
|
|
|
|
[HttpGet]
|
|
public ActionResult Remove(int id = 0)
|
|
{
|
|
this.equipmentsManager.Remove(id);
|
|
|
|
return this.RedirectToAction(nameof(Index));
|
|
}
|
|
|
|
[HttpGet]
|
|
public ActionResult Set(int id = 0)
|
|
{
|
|
this.equipmentsManager.SetInspected(id);
|
|
|
|
if (id == 0)
|
|
{
|
|
return this.RedirectToAction(nameof(Index));
|
|
}
|
|
|
|
return this.RedirectToAction(nameof(Index), new { id });
|
|
}
|
|
|
|
public ActionResult Sidebar()
|
|
{
|
|
var model = this.equipmentsManager
|
|
.SelectAll()
|
|
.OrderBy(x => x.SoftwareId)
|
|
.ThenBy(x => x.Pruefmittel)
|
|
.GroupBy(x => x.SoftwareId)
|
|
.Select(x => new Pruefstation
|
|
{
|
|
SoftwareId = x.Key,
|
|
Pruefmittel = x
|
|
.Select(y => new Pruefmittel
|
|
{
|
|
Id = y.PruefmittelId,
|
|
Nr = y.PruefmittelNr,
|
|
Name = y.Pruefmittel,
|
|
})
|
|
})
|
|
.ToList();
|
|
|
|
var result = JsonConvert.SerializeObject(this.softwareManager.ListSoftwares());
|
|
var softwareItems = JsonConvert
|
|
.DeserializeObject<IEnumerable<Software>>(result)
|
|
.ToDictionary(x => x.SoftwareId, x => x.AssemblyName);
|
|
|
|
foreach (var item in model)
|
|
{
|
|
if (softwareItems.ContainsKey(item.SoftwareId))
|
|
{
|
|
item.AssemblyName = softwareItems[item.SoftwareId];
|
|
}
|
|
}
|
|
|
|
return this.PartialView(model);
|
|
}
|
|
|
|
public ActionResult Software(int selected)
|
|
{
|
|
var result = JsonConvert.SerializeObject(this.softwareManager.ListSoftwares());
|
|
var softwareItems = JsonConvert.DeserializeObject<IEnumerable<SoftwareSelectListItem>>(result);
|
|
|
|
foreach (var softwareItem in softwareItems)
|
|
{
|
|
softwareItem.Selected = softwareItem.Value == $"{selected}";
|
|
}
|
|
|
|
return this.PartialView(softwareItems);
|
|
}
|
|
}
|
|
|
|
public class Software
|
|
{
|
|
public short SoftwareId { get; set; }
|
|
|
|
public string AssemblyName { get; set; }
|
|
}
|
|
|
|
public class SoftwareSelectListItem : SelectListItem
|
|
{
|
|
public short SoftwareId
|
|
{
|
|
get => short.TryParse(this.Value, out var value) ? value : (short)0;
|
|
set => this.Value = value.ToString();
|
|
}
|
|
|
|
public string AssemblyName
|
|
{
|
|
get => this.Text;
|
|
set => this.Text = value;
|
|
}
|
|
}
|
|
|
|
public class Pruefstation
|
|
{
|
|
public short SoftwareId { get; set; }
|
|
|
|
public string AssemblyName { get; set; }
|
|
|
|
public IEnumerable<Pruefmittel> Pruefmittel { get; set; }
|
|
}
|
|
|
|
public class Pruefmittel
|
|
{
|
|
public int Id { get; set; }
|
|
|
|
public string Nr { get; set; }
|
|
|
|
public string Name { get; set; }
|
|
}
|
|
} |