180 lines
6.9 KiB
C#
180 lines
6.9 KiB
C#
using Core.DTO;
|
|
using Core;
|
|
using LiMan.APi.Data;
|
|
using LiMan.DB.DTO;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using NLog;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using System.Linq;
|
|
using LiMan.DB.DBModels;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace LiMan.APi.Controllers
|
|
{
|
|
/// <summary>
|
|
/// Controller gestione RELEASE applicativi
|
|
/// </summary>
|
|
[Route("api/release")]
|
|
[ApiController]
|
|
public class ReleaseController : ControllerBase
|
|
{
|
|
#region Public Constructors
|
|
|
|
/// <summary>
|
|
/// Init generico
|
|
/// </summary>
|
|
/// <param name="DataService"></param>
|
|
public ReleaseController(ApiDataService DataService)
|
|
{
|
|
dataService = DataService;
|
|
Log.Info("Avviata classe ReleaseController");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Recupera elenco dati licenza Applicativi (completo)
|
|
/// GET api/Release/EgtBW
|
|
/// </summary>
|
|
/// <param name="id">Codice Applicazione</param>
|
|
/// <returns></returns>
|
|
[HttpGet("{id}")]
|
|
public async Task<List<ReleaseDTO>> Get(string id)
|
|
{
|
|
var result = await dataService.ReleaseGetByApp(id);
|
|
await dataService.recordCall(id, id, $"GET:api/Release/{id}");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco dati licenza Applicativi data versione minima
|
|
/// GET api/Release/EgtBW
|
|
/// </summary>
|
|
/// <param name="id">Codice Applicazione</param>
|
|
/// <param name="VersMin">Versione minima richiesta (attuale)</param>
|
|
/// <returns></returns>
|
|
[HttpGet("filt/{id}")]
|
|
public async Task<List<ReleaseDTO>> GetFilt(string id, string VersMin)
|
|
{
|
|
var result = await dataService.ReleaseGetByAppVers(id, VersMin);
|
|
await dataService.recordCall(id, id, $"GET:api/Release/filt/{id}");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco dati licenza Applicativi data versione minima + vers limite
|
|
/// GET api/Release/EgtBW
|
|
/// </summary>
|
|
/// <param name="id">Codice Applicazione</param>
|
|
/// <param name="VersMin">Versione minima richiesta (attuale)</param>
|
|
/// <param name="VersMax">Versione massima consentita</param>
|
|
/// <returns></returns>
|
|
[HttpGet("filtLimit/{id}")]
|
|
public async Task<List<ReleaseDTO>> GetFiltLimit(string id, string VersMin, string VersMax)
|
|
{
|
|
var result = await dataService.ReleaseGetByAppVersLimit(id, VersMin, VersMax);
|
|
await dataService.recordCall(id, id, $"GET:api/Release/filtLimit/{id}");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Richiesta di registrazione di una nuova Release applicativa
|
|
/// POST api/release/save
|
|
/// </summary>
|
|
/// <param name="CurrRequest">Obj Richiesta</param>
|
|
[HttpPost("save")]
|
|
public async Task<ReleaseDTO> save([FromBody] AppRelVersion CurrRequest)
|
|
{
|
|
ReleaseDTO result = new ReleaseDTO()
|
|
{
|
|
CodApp = CurrRequest.CodApp,
|
|
ReleaseDate = CurrRequest.ReleaseDate,
|
|
VersNum = CurrRequest.VersNum,
|
|
VersText = CurrRequest.VersText,
|
|
RelTags = CurrRequest.RelTags.ToUpper()
|
|
};
|
|
// controllo valori
|
|
if (CurrRequest.IsValid)
|
|
{
|
|
// verifica preliminare licenza x upload
|
|
var licUploader = await dataService.LicenzeSearch(CurrRequest.CodInst, CurrRequest.UplAppID, CurrRequest.MasterKey, false);
|
|
if (licUploader != null && licUploader.Count > 0)
|
|
{
|
|
|
|
// in primis cerco app...
|
|
var appList = await dataService.ApplicativiGetAll();
|
|
ApplicativoModel recApp = new ApplicativoModel();
|
|
if (appList != null)
|
|
{
|
|
recApp = appList.FirstOrDefault(x => x.CodApp == CurrRequest.CodApp);
|
|
}
|
|
// nel caso mancasse la aggiungo
|
|
if (recApp == null || string.IsNullOrEmpty(recApp.CodApp) || recApp.CodApp != CurrRequest.CodApp)
|
|
{
|
|
recApp = new ApplicativoModel()
|
|
{
|
|
CodApp = CurrRequest.CodApp,
|
|
Descrizione = "Nuova APP da POST api/release/save",
|
|
TplConnString = "",
|
|
Tipo = CurrRequest.Tipo
|
|
};
|
|
await dataService.ApplicativoUpsert(recApp);
|
|
}
|
|
//converto in una release...
|
|
ReleaseModel newRec = new ReleaseModel()
|
|
{
|
|
CodApp = CurrRequest.CodApp,
|
|
ReleaseDate = CurrRequest.ReleaseDate,
|
|
RelTags = CurrRequest.RelTags.ToUpper(),
|
|
VersNum = CurrRequest.VersNum,
|
|
VersText = CurrRequest.VersText
|
|
};
|
|
// registro versione eventualmente gestendo nuovo applicativo
|
|
var insRes = await dataService.ReleaseUpsert(newRec);
|
|
if (insRes)
|
|
{
|
|
Log.Info($"Release recorded | {CurrRequest.CodApp} | {CurrRequest.VersNum} | {CurrRequest.VersText} | {CurrRequest.ReleaseDate} | {CurrRequest.RelTags}");
|
|
}
|
|
}
|
|
// recupero vers applicativo...
|
|
var rawResult = await dataService.ReleaseGetByApp(CurrRequest.CodApp);
|
|
if (rawResult != null && rawResult.Count > 0)
|
|
{
|
|
result = rawResult.Where(x => x.VersText == CurrRequest.VersText).FirstOrDefault();
|
|
}
|
|
// fisso nostra install
|
|
await dataService.recordCall(CurrRequest.CodInst, CurrRequest.CodApp, $"POST:api/release/save:{CurrRequest.CodApp}");
|
|
}
|
|
else
|
|
{
|
|
Log.Error($"Errore: licenza UpdateManager non trovata | {CurrRequest.MasterKey}");
|
|
await dataService.recordCall(CurrRequest.CodInst, CurrRequest.CodApp, $"ERROR POST:api/release/save:{CurrRequest.CodApp} | {CurrRequest.MasterKey}");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
/// <summary>
|
|
/// Dataservice x accesso DB
|
|
/// </summary>
|
|
protected ApiDataService dataService { get; set; }
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Private Fields
|
|
|
|
/// <summary>
|
|
/// Classe per logging
|
|
/// </summary>
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |