using GPW.CORE.Api.Data;
using GPW.CORE.Data;
using GPW.CORE.Data.DbModels;
using Microsoft.AspNetCore.Mvc;
using NLog;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace GPW.CORE.Api.Controllers
{
///
/// Controller interazione VC19
///
[Route("api/VC19")]
[ApiController]
public class VC19Controller : ControllerBase
{
#region Private Fields
///
/// Classe per logging
///
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
#endregion Private Fields
#region Public Constructors
///
/// Init generico
///
///
public VC19Controller(ApiDataService DataService)
{
_DataService = DataService;
Log.Info("Avviata classe VC19Controller");
}
#endregion Public Constructors
#region Protected Properties
///
/// Dataservice x accesso DB
///
protected ApiDataService _DataService { get; set; }
#endregion Protected Properties
#region Public Methods
///
/// Recupera ultimi 20 check in ordine cronologico inverso
///
///
[HttpGet]
public async Task> Get()
{
var result = await _DataService.ChecksGetLast(20);
return result;
}
///
/// Recupera ultimo mese di check x dipendente indicato da ID
/// GET api/VC19/5
///
///
///
[HttpGet("{id}")]
public async Task> Get(int id)
{
var result = await _DataService.ChecksGetByDip(id);
return result;
}
///
/// Invio record decodificato da classe DCC
///
///
///
[HttpPost]
public async Task Post(DCCDecode DecodedData)
{
VC19Check answ = new VC19Check()
{
Result = "KO"
};
var result = await _DataService.InsertCheck(DecodedData, "10.74.82.255");
if (result)
{
answ = new VC19Check
{
DTRecord = DateTime.Now,
CheckRecorded = true,
TimbrRecorder = true,
Result = $"OK, Check Recorded for {DecodedData.nam.fn} {DecodedData.nam.gn} {DecodedData.dob:yyyy.MM.dd}"
};
}
else
{ }
return answ;
}
///
/// Invio DI TEST record manuale
///
///
///
[HttpPut]
public async Task Put(TestUser id)
{
VC19Check answ = new VC19Check()
{
Result = "KO"
};
var result = await _DataService.InsertManual((int)id, "10.74.82.255");
answ = new VC19Check
{
DTRecord = DateTime.Now,
CheckRecorded = true,
TimbrRecorder = true,
Result = $"OK, Check Recorded for id {id}"
};
return answ;
}
#endregion Public Methods
}
}