forked from ddrilling/AsbCloudServer
Метод UpdateWellStateAsync контроллера WellController
This commit is contained in:
parent
7aadcbe69b
commit
46799baace
@ -1,8 +1,10 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -112,5 +114,35 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return Ok(result);
|
return Ok(result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обновляет статус скважины
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">ключ скважины</param>
|
||||||
|
/// <param name="idState">статус: 0 - Неизвестно, 1 - В работе, 2 - Завершена.</param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPut("{idWell}/state")]
|
||||||
|
[Permission]
|
||||||
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> 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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user