using Core; using LiMan.APi.Data; using LiMan.DB.DBModels; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using NLog; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace LiMan.APi.Controllers { /// /// Controller livello APPLICAZIONE /// [Route("api/enroller")] [ApiController] public class EnrollerController : ControllerBase { #region Public Constructors /// /// Init generico /// /// public EnrollerController(ApiDataService DataService) { dataService = DataService; Log.Info("Avviata classe ApplicazioneController"); } #endregion Public Constructors #region Public Methods /// /// Recupera record di enroll di una richiesta x ricavarne ID licenza da applicare /// /// ID richiesta /// passcode associato /// [HttpGet("{id}")] public async Task Get(string id, int passcode) { string CodInst = "NA"; string CodApp = "Updater"; int reqId = 0; int.TryParse(id, out reqId); EnrollRequestModel reqRec = await dataService.EnrollReqGetById(reqId); // solo se il passcode è corretto restituisco record, altrimenti fake one... if (reqRec != null && reqRec.Passcode != passcode) { reqRec = new EnrollRequestModel() { IdReq = reqId }; } await dataService.recordCall(CodInst, CodApp, $"GET:api/enroller/{id}"); return reqRec; } /// /// Richiesta di un record con codice TOTP per l'enroll di un app client /// POST api/enroller/getNewCode /// [HttpPost("getEnrollRec")] public async Task GetEnrollRec([FromBody] Dictionary MachineInfo) { string CodInst = "NA"; string CodApp = "Updater"; var newRec = await dataService.EnrollReqCreate(MachineInfo); await dataService.recordCall(CodInst, CodApp, $"GET:api/enroller/GetEnrollRec"); return newRec; } #endregion Public Methods #region Protected Properties /// /// Dataservice x accesso DB /// protected ApiDataService dataService { get; set; } #endregion Protected Properties #region Private Fields /// /// Classe per logging /// private static Logger Log = LogManager.GetCurrentClassLogger(); /// /// Generatore pseudocasuale /// private Random rnd = new Random(); #endregion Private Fields } }