53 lines
1.6 KiB
C#
53 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;
|
|||
|
|
|
|||
|
|
namespace PARR.API.Controllers.V1
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Периоды распределения РР
|
|||
|
|
/// </summary>
|
|||
|
|
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
|||
|
|
public class DistributionPeriodController : BaseApiController
|
|||
|
|
{
|
|||
|
|
private readonly IDistributionPeriodService distributionPeriodService;
|
|||
|
|
private readonly IMapper mapper;
|
|||
|
|
|
|||
|
|
public DistributionPeriodController(
|
|||
|
|
IDistributionPeriodService distributionPeriodService,
|
|||
|
|
IMapper mapper
|
|||
|
|
)
|
|||
|
|
{
|
|||
|
|
this.distributionPeriodService = distributionPeriodService;
|
|||
|
|
this.mapper = mapper;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Список периодов распределения
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
[HttpGet(ApiRoutes.DistributionPeriod.GetAll)]
|
|||
|
|
public async Task<IActionResult> GetAll()
|
|||
|
|
{
|
|||
|
|
var periods = await distributionPeriodService.Get()
|
|||
|
|
.OrderBy(t => t.Name)
|
|||
|
|
.ToListAsync();
|
|||
|
|
|
|||
|
|
if (!periods.Any())
|
|||
|
|
return NoContent();
|
|||
|
|
|
|||
|
|
var response = mapper.Map<List<DistributionPeriodResponse>>(periods);
|
|||
|
|
|
|||
|
|
return Ok(new Response<List<DistributionPeriodResponse>>(response, true));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|