58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
using AutoMapper;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using PARR.API.Contracts.V1;
|
|
using PARR.API.Contracts.V1.Responses;
|
|
using PARR.API.Contracts.V1.Responses.Base;
|
|
using PARR.API.Controllers.V1.Base;
|
|
using PARR.Constants;
|
|
using PARR.DAL.Services.Interfaces.Unit;
|
|
|
|
namespace PARR.API.Controllers.V1
|
|
{
|
|
/// <summary>
|
|
/// Список КИИ ЭК
|
|
/// </summary>
|
|
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
|
public class KiiUnitController : BaseApiController
|
|
{
|
|
private readonly IMapper mapper;
|
|
private readonly IUnitKiiUnitService unitKiiUnitService;
|
|
|
|
public KiiUnitController(
|
|
IMapper mapper,
|
|
IUnitKiiUnitService unitKiiUnitService
|
|
)
|
|
{
|
|
this.mapper = mapper;
|
|
this.unitKiiUnitService = unitKiiUnitService;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Список КИИ ЭК
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet(ApiRoutes.KiiUnit.GetAll)]
|
|
public async Task<IActionResult> GetAll()
|
|
{
|
|
var query = unitKiiUnitService.Get()
|
|
.Include(t => t.Unit)
|
|
.Select(t => t.Unit)
|
|
.OrderBy(t => t.Name);
|
|
|
|
var units = await query.ToListAsync();
|
|
|
|
if (!units.Any())
|
|
return NoContent();
|
|
|
|
var response = mapper.Map<List<UnitBaseResponse>>(units);
|
|
|
|
return Ok(new Response<List<UnitBaseResponse>>(response, true));
|
|
}
|
|
|
|
|
|
}
|
|
}
|