59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
namespace LaaProduction.Web.API.Personalization
|
|
{
|
|
using LaaProduction.Personalization.Interfaces;
|
|
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;
|
|
|
|
public RolesController()
|
|
=> this.employeesManager = LaaServiceProvider.GetService<IEmployeesManager>();
|
|
|
|
[HttpGet]
|
|
public IHttpActionResult Get()
|
|
{
|
|
var employeeRoles = this.employeesManager
|
|
.GetRoles()
|
|
.ToList();
|
|
|
|
return this.Json(employeeRoles);
|
|
}
|
|
|
|
[HttpGet]
|
|
public IHttpActionResult Find(short id)
|
|
{
|
|
var employeeRoles = this.employeesManager.GetRoles(id);
|
|
|
|
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; }
|
|
}
|
|
}
|