DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/WellFinalDocumentsController.cs

120 lines
4.1 KiB
C#
Raw Normal View History

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using System.Threading;
using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
namespace AsbCloudWebApi.Controllers
{
/// <summary>
/// Дело скважины
/// </summary>
[Route("api/wellFinalDocuments")]
[ApiController]
[Authorize]
public class WellFinalDocumentsController : ControllerBase
{
private readonly IWellFinalDocumentsService wellFinalDocumentsService;
public WellFinalDocumentsController(IWellFinalDocumentsService wellFinalDocumentsService)
{
this.wellFinalDocumentsService = wellFinalDocumentsService;
}
/// <summary>
/// Получение всех записей
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet]
[Permission]
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token = default)
{
var data = await this.wellFinalDocumentsService.GetByWellId(idWell, token);
return Ok(data);
}
/// <summary>
/// Получение списка ответственных
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet]
[Permission]
[Route("getResponsibles")]
public async Task<IActionResult> GetResponsiblesAsync(int idWell, CancellationToken token = default)
{
var data = await this.wellFinalDocumentsService.GetListResponsiblesAsync(idWell, token);
return Ok(data);
}
/// <summary>
/// Добавление записи
/// </summary>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpPut]
[Permission]
public async Task<IActionResult> InsertRangeAsync(List<WellFinalDocumentsDBDto> dtos, CancellationToken token = default)
{
var data = await this.wellFinalDocumentsService.InsertRangeAsync(dtos, token);
return Ok(data);
}
/// <summary>
/// Удалить запись
/// </summary>
/// <param name="iDdto"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpDelete]
[Permission]
public async Task<IActionResult> DeleteAsync(int iDdto, CancellationToken token = default)
{
var data = await this.wellFinalDocumentsService.DeleteAsync(iDdto, token);
return Ok(data);
}
/// <summary>
/// Получение истории файлов
/// </summary>
/// <param name="idWell"></param>
/// <param name="idCategory"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet]
[Permission]
[Route("getHistoryFileByIdCategory")]
public async Task<IActionResult> GetHistoryFileByIdCategory(int idWell,
int idCategory,
CancellationToken token = default)
{
var data = await this.wellFinalDocumentsService.GetHistoryFileByIdCategory(idWell, idCategory, token);
return Ok(data);
}
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="idDto"></param>
/// <param name="file"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpPost]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> SaveFilesAsync(int idDto,
IFormFile file, CancellationToken token = default)
{
var fileStream = file.OpenReadStream();
var data = await this.wellFinalDocumentsService.SaveCategoryFile(idDto, fileStream, file.FileName, token);
return Ok(data);
}
}
}