using Core; using Core.DTO; using LiMan.APi.Data; using LiMan.DB.DTO; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using NLog; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace LiMan.APi.Controllers { /// /// Controller livello TICKET /// [Route("api/ticket")] [ApiController] public class TicketController : ControllerBase { #region Private Fields /// /// Classe per logging /// private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); #endregion Private Fields #region Public Constructors /// /// Init generico /// /// public TicketController(ApiDataService DataService) { dataService = DataService; Log.Info("Avviata classe TicketController"); } #endregion Public Constructors #region Protected Properties /// /// Dataservice x accesso DB /// protected ApiDataService dataService { get; set; } #endregion Protected Properties #region Public Methods /// GET api/ticket/id /// /// Recupera elenco Ticket dato cliente / applicazione / chiave /// /// Codice cliente/Installazione /// Codice Applicazione /// Master Key /// [HttpGet("{id}")] public async Task> Get(string id, string CodApp, string Chiave) { var result = await dataService.TicketByCliente(id, CodApp, Chiave); await dataService.recordCall(id, CodApp, $"GET:api/ticket:{Chiave}"); return result; } /// /// Richiesta di registrazione ticket supporto /// /// Obj Richiesta // POST api/ticket/sendReq [HttpPost("sendReq")] public async Task sendReq([FromBody] SupportRequest CurrRequest) { TicketDTO result = new TicketDTO(); // controllo valori if (CurrRequest.IsValid) { // registro richiesta var insRes = await dataService.TicketAdd(CurrRequest); } // restituisco richieste aperte var rawResult= await dataService.TicketByCliente(CurrRequest.CodInst, CurrRequest.CodApp, CurrRequest.MasterKey, 1); result = rawResult.FirstOrDefault(); Log.Info($"Ticket generated: {result.IdxTicket} | CI: {CurrRequest.CodInst} | CA: {CurrRequest.CodApp}"); await dataService.recordCall(CurrRequest.CodInst, CurrRequest.CodApp, $"POST:api/ticket/sendReq:{CurrRequest.MasterKey}"); return result; } #endregion Public Methods } }