4fda312aac
- altri metodi tracciati - modifica json x prod - aggiunta Async vari
115 lines
3.2 KiB
C#
115 lines
3.2 KiB
C#
using GWMS.Data.DatabaseModels;
|
|
using GWMS.UI.Data;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
|
|
|
namespace GWMS.UI.Controllers
|
|
{
|
|
[Route("api/PlantLog")]
|
|
[ApiController]
|
|
public class PlantLogController : ControllerBase
|
|
{
|
|
#region Private Fields
|
|
|
|
/// <summary>
|
|
/// Classe per logging
|
|
/// </summary>
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Public Constructors
|
|
|
|
public PlantLogController(GWMSDataService DataService)
|
|
{
|
|
_DataService = DataService;
|
|
Log.Debug("Avviata classe PlantDataController");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Protected Properties
|
|
|
|
protected GWMSDataService _DataService { get; set; }
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Public Methods
|
|
|
|
// DELETE api/PlantLog/5
|
|
[HttpDelete("{id}")]
|
|
public void Delete(int id)
|
|
{
|
|
Log.Debug($"Chiamata Delete | {id}");
|
|
}
|
|
|
|
// GET: api/PlantLog
|
|
[HttpGet]
|
|
public async Task<List<PlantLogModel>> Get()
|
|
{
|
|
//Log.Debug("Chiamata Get");
|
|
// arrotondo ai 5 minuti
|
|
DateTime adesso = DateTime.Now;
|
|
int dayHour = adesso.Hour;
|
|
int dayMin = (adesso.Minute / 5) * 5;
|
|
DateTime limite = DateTime.Today.AddHours(dayHour).AddMinutes(dayMin);
|
|
|
|
// serializzo i dati di PlantDTO dell'impianto richiesto
|
|
var ListRecords = await _DataService.PlantLogGetFiltAsync(0, limite, 100);
|
|
return ListRecords;
|
|
}
|
|
|
|
// GET api/PlantLog/5
|
|
[HttpGet("{id}")]
|
|
public async Task<List<PlantLogModel>> Get(int id)
|
|
{
|
|
Log.Debug($"Chiamata Get | {id}");
|
|
// arrotondo ai 5 minuti
|
|
DateTime adesso = DateTime.Now;
|
|
int dayHour = adesso.Hour;
|
|
int dayMin = (adesso.Minute / 5) * 5;
|
|
DateTime limite = DateTime.Today.AddHours(dayHour).AddMinutes(dayMin);
|
|
|
|
// serializzo i dati di PlantDTO dell'impianto richiesto
|
|
var ListRecords = await _DataService.PlantLogGetFiltAsync(id, limite, 100);
|
|
return ListRecords;
|
|
}
|
|
|
|
// POST api/PlantLog
|
|
[HttpPost]
|
|
public async Task<ActionResult> Post([FromBody] List<PlantLogModel> newItems)
|
|
{
|
|
Log.Debug("Chiamata Post");
|
|
bool fatto = false;
|
|
// verifico ci sia valore
|
|
if (newItems != null)
|
|
{
|
|
fatto = await _DataService.PlantLogInsertAsync(newItems);
|
|
}
|
|
if (fatto)
|
|
{
|
|
return Ok();
|
|
}
|
|
else
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
// PUT api/PlantLog/5
|
|
[HttpPut("{id}")]
|
|
public void Put(int id, [FromBody] string value)
|
|
{
|
|
Log.Debug($"Chiamata Put | {id}");
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |