Bozza controller salvataggio log macchina
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
using MagMan.Core.DTO;
|
||||
using MagMan.Core;
|
||||
using MagMan.Data.Admin.DbModels;
|
||||
using MagMan.Data.Admin.Services;
|
||||
using MagMan.Data.Tenant.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using MagMan.Data.Tenant.DbModels;
|
||||
|
||||
namespace MagMan.UI.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class LogMachineController : ControllerBase
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public LogMachineController(MTAdminService MTDataService, TenantService TDataService)
|
||||
{
|
||||
MTAdmService = MTDataService;
|
||||
TService = TDataService;
|
||||
// json serializer... FIX errore loop circolare https://www.ryadel.com/en/jsonserializationexception-self-referencing-loop-detected-error-fix-entity-framework-asp-net-core/
|
||||
JSSettings = new JsonSerializerSettings()
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
||||
};
|
||||
Log.Info("Avviata classe LogMachineController");
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Controllo status Alive
|
||||
/// GET: api/LogMachine/alive
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("alive")]
|
||||
public string alive()
|
||||
{
|
||||
return $"OK";
|
||||
}
|
||||
|
||||
// GET api/LogMachine
|
||||
[HttpGet]
|
||||
public async Task<List<LogMachineModel>> Get()
|
||||
{
|
||||
// se non ho chiave --> vuoto!
|
||||
List<LogMachineModel> ListRecords = new List<LogMachineModel>();
|
||||
await Task.Delay(100);
|
||||
return ListRecords;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco ultimi valori LogMachineModel dato RestToken
|
||||
/// </summary>
|
||||
/// <param name="id">Rest Token cliente</param>
|
||||
/// <param name="KeyNum">Chiave associata ai progetti</param>
|
||||
/// <returns></returns>
|
||||
// GET api/LogMachine/2cba60c7-7be4-40b1-aa0d-52e7c71fc1a7
|
||||
[HttpGet("{id}")]
|
||||
public async Task<List<LogMachineModel>> Get(string id, int KeyNum, int numVal)
|
||||
{
|
||||
List<LogMachineModel> ListRecords = new List<LogMachineModel>();
|
||||
#if false
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
{
|
||||
// in primis recupero codice chiave da token...
|
||||
int nKey = await MTAdmService.MainKeyByToken(id);
|
||||
var rawList = await TService.ProjectGetAll(nKey);
|
||||
ListRecords = rawList.Select(x => TService.ProjectToDto(x)).ToList();
|
||||
}
|
||||
#endif
|
||||
return ListRecords;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa una chiamata POST per l'invio di un oggetto di upsert progetto
|
||||
/// PUT: api/Inventory/upsert/00000000-0000-0000-0000-000000000000
|
||||
/// </summary>
|
||||
/// <param name="id">token comunicazione</param>
|
||||
/// <returns>ID del progetto creato da usare come CloudId</returns>
|
||||
[HttpPost("upsert/{id}")]
|
||||
public async Task<int> upsert(string id, [FromBody] RestPayload.LogData rawData)
|
||||
{
|
||||
int answ = 0;
|
||||
// verifico ci sia valore
|
||||
if (!string.IsNullOrEmpty(id) && rawData != null && rawData.LogList != null)
|
||||
{
|
||||
// in primis recupero codice chiave da token...
|
||||
int nKey = await MTAdmService.MainKeyByToken(id);
|
||||
if (nKey > 0)
|
||||
{
|
||||
#if false
|
||||
// converto ProjDto --> DB
|
||||
var currRec = TService.ProjectFromDto(rawData.Project);
|
||||
try
|
||||
{
|
||||
answ = await TService.ProjectUpsert(nKey, currRec);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"ProjectsController.upsert | Errore in fase salvataggio ProjectDTO{Environment.NewLine}{exc}");
|
||||
}
|
||||
// resetto cache redis
|
||||
await MTAdmService.FlushRedisCache();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static JsonSerializerSettings? JSSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Classe per logging
|
||||
/// </summary>
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private MTAdminService MTAdmService { get; set; } = null!;
|
||||
private TenantService TService { get; set; } = null!;
|
||||
|
||||
#endregion Private Properties
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user