170 lines
4.4 KiB
C#
170 lines
4.4 KiB
C#
namespace LaaProduction.Web.API.Personalization
|
|
{
|
|
using LaaProduction.Personalization.Interfaces;
|
|
using LaaProduction.Web.App_Infrastructure;
|
|
using LaaProductionDI;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Web.Http;
|
|
|
|
[AuthorizeBearer]
|
|
[RoutePrefix("api/Personalization/Software")]
|
|
public class SoftwareController : ApiController
|
|
{
|
|
private readonly ISoftwareManager softwareManager;
|
|
|
|
public SoftwareController()
|
|
=> this.softwareManager = LaaServiceProvider.GetService<ISoftwareManager>();
|
|
|
|
[HttpGet]
|
|
[Route(nameof(Functions))]
|
|
public IHttpActionResult Functions()
|
|
{
|
|
var employeeRoles = this.softwareManager.GetFunctions();
|
|
|
|
return this.Json(employeeRoles);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route(nameof(Access))]
|
|
public IHttpActionResult Access()
|
|
{
|
|
var bearer = this.User.GetNameIdentifier();
|
|
var functions = this.softwareManager.GetFunctions(bearer);
|
|
|
|
return this.Json(functions);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route(nameof(List))]
|
|
public IHttpActionResult List()
|
|
{
|
|
var softwares = this.softwareManager.ListSoftwares();
|
|
|
|
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; }
|
|
}
|
|
|
|
public class SoftwareLoginModel
|
|
{
|
|
public string Software { get; set; }
|
|
|
|
public IEnumerable<string> Functions { get; set; }
|
|
}
|
|
}
|