DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/LastDataController.cs
2021-08-02 12:59:43 +05:00

45 lines
1.4 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using AsbCloudApp.Services;
namespace AsbCloudWebApi.Controllers
{
[ApiController]
[Authorize]
public abstract class LastDataController<T> : ControllerBase where T : class
{
private readonly ILastDataService<T> lastDataService;
private readonly IWellService wellService;
public LastDataController(ILastDataService<T> lastDataService, IWellService wellService)
{
this.lastDataService = lastDataService;
this.wellService = wellService;
}
[HttpGet]
public IActionResult Get([FromRoute] int idWell, [FromQuery] int idCategory)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
return Forbid();
lastDataService.Get(idWell, idCategory);
return Ok();
}
[HttpPost]
public IActionResult Put([FromRoute] int idWell, [FromQuery] int idCategory, [FromForm] T data)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
return Forbid();
lastDataService.Upsert(idWell, idCategory, data);
return Ok();
}
}
}