From 46799baace6e4e33dc3bd60282e08f05618f5a74 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Tue, 2 May 2023 16:47:16 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D1=82=D0=BE=D0=B4=20UpdateWellStat?= =?UTF-8?q?eAsync=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5?= =?UTF-8?q?=D1=80=D0=B0=20WellController?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudWebApi/Controllers/WellController.cs | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/AsbCloudWebApi/Controllers/WellController.cs b/AsbCloudWebApi/Controllers/WellController.cs index e92840ee..627b2f88 100644 --- a/AsbCloudWebApi/Controllers/WellController.cs +++ b/AsbCloudWebApi/Controllers/WellController.cs @@ -1,8 +1,10 @@ using AsbCloudApp.Data; using AsbCloudApp.Services; +using AsbCloudDb.Model; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Threading; using System.Threading.Tasks; @@ -112,5 +114,35 @@ namespace AsbCloudWebApi.Controllers return Ok(result); } + + /// + /// Обновляет статус скважины + /// + /// ключ скважины + /// статус: 0 - Неизвестно, 1 - В работе, 2 - Завершена. + /// + /// + [HttpPut("{idWell}/state")] + [Permission] + [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] + public async Task UpdateWellStateAsync(int idWell, + [Range(0, 2, ErrorMessage = "Статус некорректен")] int idState, + CancellationToken token = default) + { + var idCompany = User.GetCompanyId(); + + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + idWell, token).ConfigureAwait(false)) + return Forbid(); + + var dto = wellService.GetOrDefault(idWell)!; + dto.IdState = idState; + + var result = await wellService.UpdateAsync(dto, token) + .ConfigureAwait(false); + + return Ok(result); + + } } }