690 lines
26 KiB
C#
690 lines
26 KiB
C#
using LiMan.DB.DBModels;
|
|
using LiMan.DB.DTO;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LiMan.DB.Controllers
|
|
{
|
|
public class DbController : IDisposable
|
|
{
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration;
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Public Constructors
|
|
|
|
public DbController(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Elimino una licenza da quelle attivate (SE scaduto veto)
|
|
/// </summary>
|
|
/// <param name="ParamDict">Dizionario delle Licenze da eliminare</param>
|
|
/// <param name="MasterKey">Chiave Master</param>
|
|
public bool AttivazioniDelete(Dictionary<string, string> ParamDict, string MasterKey)
|
|
{
|
|
bool fatto = false;
|
|
LicenzaModel mainLic = new LicenzaModel();
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
DateTime oggi = DateTime.Today;
|
|
List<SubLicenzaModel> items2del = new List<SubLicenzaModel>();
|
|
// ciclo x ogni licenze a vedere SE sia eliminabile...
|
|
foreach (var item in ParamDict)
|
|
{
|
|
// calcolo DTO Attivazione
|
|
var itemsTgt = localDbCtx
|
|
.DbSetSubLicenze
|
|
.Where(x => x.CodImpiego == item.Key && x.Chiave == item.Value && x.LicenzaNav.Chiave == MasterKey && x.VetoUnlock < oggi)
|
|
.ToList();
|
|
// se trovate aggiungo ad elenco...
|
|
if (itemsTgt != null && itemsTgt.Count > 0)
|
|
{
|
|
items2del.AddRange(itemsTgt);
|
|
}
|
|
}
|
|
|
|
// se ho qualcosa procedo...
|
|
if (items2del != null && items2del.Count > 0)
|
|
{
|
|
localDbCtx
|
|
.DbSetSubLicenze
|
|
.RemoveRange(items2del);
|
|
// salvo
|
|
localDbCtx.SaveChanges();
|
|
fatto = true;
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista attivfazioni x licenza
|
|
/// </summary>
|
|
/// <param name="idxLic"></param>
|
|
/// <returns></returns>
|
|
public List<SubLicenzaModel> AttivazioniGetByLic(int idxLic)
|
|
{
|
|
List<SubLicenzaModel> dbResult = new List<SubLicenzaModel>();
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
DateTime oggi = DateTime.Today;
|
|
dbResult = localDbCtx
|
|
.DbSetSubLicenze
|
|
.Where(x => x.IdxLic == idxLic)
|
|
.OrderBy(o => o.VetoUnlock)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elimino le licenze con veto scaduto
|
|
/// </summary>
|
|
/// <param name="MasterKey">Chiave Master</param>
|
|
public bool AttivazioniResetAvail(string MasterKey)
|
|
{
|
|
bool fatto = false;
|
|
LicenzaModel mainLic = new LicenzaModel();
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
DateTime oggi = DateTime.Today;
|
|
|
|
// calcolo DTO Attivazione
|
|
var item2Del = localDbCtx
|
|
.DbSetSubLicenze
|
|
.Where(x => x.LicenzaNav.Chiave == MasterKey && x.VetoUnlock < oggi)
|
|
.ToList();
|
|
// se ho qualcosa procedo...
|
|
if (item2Del != null && item2Del.Count > 0)
|
|
{
|
|
localDbCtx
|
|
.DbSetSubLicenze
|
|
.RemoveRange(item2Del);
|
|
// salvo
|
|
localDbCtx.SaveChanges();
|
|
}
|
|
// comunque true se ci ha provato
|
|
fatto = true;
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Cerca di aggiungere sul DB le attivazioni richieste
|
|
/// </summary>
|
|
/// <param name="MasterKey">Master Lic</param>
|
|
/// <param name="ParamDict">Elenco codici impiego (key) + valori in formato dizionari</param>
|
|
/// <param name="numDayVeto">num gg di veto da impostare</param>
|
|
/// <returns></returns>
|
|
public bool AttivazioniTryAdd(string MasterKey, Dictionary<string, string> ParamDict, int numDayVeto)
|
|
{
|
|
bool answ = false;
|
|
|
|
// verifica se si può procedere...
|
|
var licenza = GetLicenza(MasterKey);
|
|
if (licenza != null)
|
|
{
|
|
var attivList = GetAttivazioniByLic(licenza.IdxLic, false);
|
|
if (licenza.IsValid && (licenza.NumLicenze >= (attivList.Count + ParamDict.Count)))
|
|
{
|
|
DateTime vetoDate = DateTime.Today.AddDays(numDayVeto);
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
// genero subLicenze...
|
|
var newRec = ParamDict
|
|
.Select(x => new SubLicenzaModel()
|
|
{
|
|
IdxLic = licenza.IdxLic,
|
|
CodImpiego = x.Key,
|
|
VetoUnlock = vetoDate,
|
|
Tipo = Enum.TipoLicenza.UserKey,
|
|
Chiave = x.Value
|
|
})
|
|
.ToList();
|
|
localDbCtx
|
|
.DbSetSubLicenze
|
|
.AddRange(newRec);
|
|
|
|
localDbCtx.SaveChanges();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore in AttivazioniTryAdd per MasterKey {MasterKey} | #rec: {ParamDict.Count}{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
public bool DbForceMigrate()
|
|
{
|
|
bool answ = false;
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
localDbCtx.DbForceMigrate();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in DbForceMigrate");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// Clear database context
|
|
//Log.Info("Dispose di GWMSController");
|
|
}
|
|
|
|
public List<ApplicativoDTO> GetApplicativiFilt(bool OnlyActive, string CodApp, string CodInst, bool hideData)
|
|
{
|
|
List<ApplicativoDTO> dbResult = new List<ApplicativoDTO>();
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
DateTime oggi = DateTime.Today;
|
|
|
|
// generazione stringhe casuali....
|
|
// https://jonathancrozier.com/blog/how-to-generate-a-random-string-with-c-sharp
|
|
StringBuilder sbRandChiave = new StringBuilder();
|
|
StringBuilder sbRandEnigma = new StringBuilder();
|
|
StringBuilder sbRandPayload = new StringBuilder();
|
|
string stdChiave = "";
|
|
string stdEnigma = "";
|
|
string stdPayLoad = "";
|
|
int stdIdxLic = 0;
|
|
DateTime stdDataEnigma = DateTime.Today;
|
|
if (hideData)
|
|
{
|
|
int numChar = 80;
|
|
Random random = new Random();
|
|
|
|
// idxLic
|
|
stdIdxLic = random.Next(50000, 100000);
|
|
|
|
// chiave random
|
|
for (int i = 0; i < numChar; i++)
|
|
{
|
|
// Generate floating point numbers
|
|
double myFloat = random.NextDouble();
|
|
// Generate the char using below logic
|
|
var myChar = Convert.ToChar(Convert.ToInt32(Math.Floor(25 * myFloat) + 65));
|
|
sbRandChiave.Append(myChar);
|
|
}
|
|
stdChiave = $"{sbRandChiave}";
|
|
|
|
// random data enigma
|
|
stdDataEnigma = DateTime.Today.AddDays(random.Next(0, 15));
|
|
|
|
// random enigma
|
|
for (int i = 0; i < numChar; i++)
|
|
{
|
|
// Generate floating point numbers
|
|
double myFloat = random.NextDouble();
|
|
// Generate the char using below logic
|
|
var myChar = Convert.ToChar(Convert.ToInt32(Math.Floor(25 * myFloat) + 65));
|
|
sbRandEnigma.Append(myChar);
|
|
}
|
|
stdEnigma = $"{sbRandEnigma}";
|
|
|
|
// random payload
|
|
for (int i = 0; i < numChar; i++)
|
|
{
|
|
// Generate floating point numbers
|
|
double myFloat = random.NextDouble();
|
|
// Generate the char using below logic
|
|
var myChar = Convert.ToChar(Convert.ToInt32(Math.Floor(25 * myFloat) + 65));
|
|
sbRandPayload.Append(myChar);
|
|
}
|
|
stdPayLoad = $"{sbRandPayload}";
|
|
}
|
|
|
|
// conteggio preliminare licenze impiegate
|
|
var countSubLic = localDbCtx
|
|
.DbSetSubLicenze
|
|
.GroupBy(x => x.IdxLic)
|
|
.Select(g => new
|
|
{
|
|
IdxLic = g.Key,
|
|
NumLic = g.Count()
|
|
});
|
|
|
|
// calcolo DTO applicativi
|
|
dbResult = localDbCtx
|
|
.DbSetLicenze
|
|
.Where(x => (x.CodApp == CodApp || string.IsNullOrEmpty(CodApp)) && (x.CodInst == CodInst || string.IsNullOrEmpty(CodInst)) && (!OnlyActive || x.Scadenza > oggi))
|
|
.OrderByDescending(o => o.Scadenza)
|
|
.Select(x => new ApplicativoDTO()
|
|
{
|
|
IdxLic = hideData ? stdIdxLic : x.IdxLic,
|
|
Chiave = hideData ? stdChiave : x.Chiave,
|
|
CodApp = x.CodApp,
|
|
CodInst = x.CodInst,
|
|
Descrizione = x.Descrizione,
|
|
Tipo = x.Tipo,
|
|
Scadenza = x.Scadenza,
|
|
NumLicenze = x.NumLicenze,
|
|
NumLicenzeAttive = countSubLic.Where(s => s.IdxLic == x.IdxLic).Select(c => c.NumLic).FirstOrDefault(),
|
|
DataEnigma = hideData ? stdDataEnigma : x.DataEnigma,
|
|
Enigma = hideData ? stdEnigma : x.Enigma,
|
|
Payload = hideData ? stdPayLoad : x.Payload
|
|
})
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<ApplicativoModel> GetApplicazioni()
|
|
{
|
|
List<ApplicativoModel> dbResult = new List<ApplicativoModel>();
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetApp
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public AttivazioneDTO GetAttivazione(string Chiave, string CodImpiego, bool hideData)
|
|
{
|
|
AttivazioneDTO dbResult = new AttivazioneDTO();
|
|
LicenzaModel mainLic = new LicenzaModel();
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
DateTime oggi = DateTime.Today;
|
|
int stdIdxLic = 0;
|
|
|
|
// generazione stringhe casuali....
|
|
// https://jonathancrozier.com/blog/how-to-generate-a-random-string-with-c-sharp
|
|
StringBuilder sbRandChiave = new StringBuilder();
|
|
string stdChiave = "";
|
|
|
|
if (hideData)
|
|
{
|
|
int numChar = 80;
|
|
Random random = new Random();
|
|
|
|
// idxLic
|
|
stdIdxLic = random.Next(50000, 100000);
|
|
|
|
// chiave random
|
|
for (int i = 0; i < numChar; i++)
|
|
{
|
|
// Generate floating point numbers
|
|
double myFloat = random.NextDouble();
|
|
// Generate the char using below logic
|
|
var myChar = Convert.ToChar(Convert.ToInt32(Math.Floor(25 * myFloat) + 65));
|
|
sbRandChiave.Append(myChar);
|
|
}
|
|
stdChiave = $"{sbRandChiave}";
|
|
}
|
|
else
|
|
{
|
|
// recupero se c'è licenza master
|
|
mainLic = localDbCtx
|
|
.DbSetLicenze
|
|
.Where(x => x.Chiave == Chiave)
|
|
.FirstOrDefault();
|
|
}
|
|
|
|
// calcolo DTO applicativi
|
|
dbResult = localDbCtx
|
|
.DbSetSubLicenze
|
|
.Where(x => x.LicenzaNav.Chiave == Chiave && x.CodImpiego == CodImpiego)
|
|
.OrderBy(o => o.VetoUnlock)
|
|
.Select(x => new AttivazioneDTO()
|
|
{
|
|
IdxLic = hideData ? stdIdxLic : x.IdxLic,
|
|
IdxSubLic = x.IdxSubLic,
|
|
CodImpiego = x.CodImpiego,
|
|
CodApp = mainLic.CodApp,
|
|
CodInst = mainLic.CodInst,
|
|
Descrizione = mainLic.Descrizione,
|
|
Tipo = x.Tipo,
|
|
Chiave = hideData ? stdChiave : x.Chiave,
|
|
VetoUnlock = x.VetoUnlock
|
|
})
|
|
.FirstOrDefault();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero da DB le attivazioni richieste
|
|
/// </summary>
|
|
/// <param name="IdxLic">Idx Licenza</param>
|
|
/// <param name="hideData">Indica se generare rand parametri sensibili</param>
|
|
public List<AttivazioneDTO> GetAttivazioniByLic(int IdxLic, bool hideData)
|
|
{
|
|
List<AttivazioneDTO> dbResult = new List<AttivazioneDTO>();
|
|
LicenzaModel mainLic = new LicenzaModel();
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
DateTime oggi = DateTime.Today;
|
|
int stdIdxLic = 0;
|
|
|
|
// generazione stringhe casuali....
|
|
// https://jonathancrozier.com/blog/how-to-generate-a-random-string-with-c-sharp
|
|
StringBuilder sbRandChiave = new StringBuilder();
|
|
string stdChiave = "";
|
|
|
|
if (hideData)
|
|
{
|
|
int numChar = 80;
|
|
Random random = new Random();
|
|
|
|
// idxLic
|
|
stdIdxLic = random.Next(50000, 100000);
|
|
|
|
// chiave random
|
|
for (int i = 0; i < numChar; i++)
|
|
{
|
|
// Generate floating point numbers
|
|
double myFloat = random.NextDouble();
|
|
// Generate the char using below logic
|
|
var myChar = Convert.ToChar(Convert.ToInt32(Math.Floor(25 * myFloat) + 65));
|
|
sbRandChiave.Append(myChar);
|
|
}
|
|
stdChiave = $"{sbRandChiave}";
|
|
}
|
|
else
|
|
{
|
|
// recupero se c'è licenza master
|
|
mainLic = localDbCtx
|
|
.DbSetLicenze
|
|
.Where(x => x.IdxLic == IdxLic)
|
|
.FirstOrDefault();
|
|
}
|
|
|
|
// calcolo DTO Attivazione
|
|
dbResult = localDbCtx
|
|
.DbSetSubLicenze
|
|
.Where(x => x.IdxLic == IdxLic)
|
|
.Select(x => new AttivazioneDTO()
|
|
{
|
|
IdxLic = hideData ? stdIdxLic : x.IdxLic,
|
|
IdxSubLic = x.IdxSubLic,
|
|
CodImpiego = x.CodImpiego,
|
|
CodApp = mainLic.CodApp,
|
|
CodInst = mainLic.CodInst,
|
|
Descrizione = mainLic.Descrizione,
|
|
Tipo = x.Tipo,
|
|
Chiave = hideData ? stdChiave : x.Chiave,
|
|
VetoUnlock = x.VetoUnlock
|
|
})
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<InstallazioneModel> GetInstallazioni()
|
|
{
|
|
List<InstallazioneModel> dbResult = new List<InstallazioneModel>();
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetInst
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public LicenzaModel GetLicenza(int IdxLic)
|
|
{
|
|
LicenzaModel dbResult = new LicenzaModel();
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetLicenze
|
|
.Where(x => x.IdxLic == IdxLic)
|
|
.FirstOrDefault();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public LicenzaModel GetLicenza(string MasterKey)
|
|
{
|
|
LicenzaModel dbResult = new LicenzaModel();
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetLicenze
|
|
.Where(x => x.Chiave == MasterKey)
|
|
.FirstOrDefault();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<LicenzaModel> GetLicenze()
|
|
{
|
|
List<LicenzaModel> dbResult = new List<LicenzaModel>();
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetLicenze
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<LicenzaModel> GetLicenzeFilt(bool OnlyActive, string CodApp, string CodInst)
|
|
{
|
|
List<LicenzaModel> dbResult = new List<LicenzaModel>();
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
DateTime oggi = DateTime.Today;
|
|
dbResult = localDbCtx
|
|
.DbSetLicenze
|
|
.Where(x => (x.CodApp == CodApp || string.IsNullOrEmpty(CodApp)) && (x.CodInst == CodInst || string.IsNullOrEmpty(CodInst)) && (!OnlyActive || x.Scadenza > oggi))
|
|
.Include(a => a.Attivazioni)
|
|
.OrderByDescending(o => o.Scadenza)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Annulla modifiche su una specifica entity (cancel update)
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <returns></returns>
|
|
public bool rollBackEntity(object item)
|
|
{
|
|
bool answ = false;
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
if (localDbCtx.Entry(item).State == EntityState.Deleted || localDbCtx.Entry(item).State == EntityState.Modified)
|
|
{
|
|
localDbCtx.Entry(item).Reload();
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in rollBackEntity{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
public bool UpsertApplicazione(ApplicativoModel updItem)
|
|
{
|
|
bool done = false;
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
ApplicativoModel currData = localDbCtx
|
|
.DbSetApp
|
|
.Where(x => x.CodApp == updItem.CodApp)
|
|
.FirstOrDefault();
|
|
if (currData != null)
|
|
{
|
|
// aggiorno valori
|
|
currData.Descrizione = updItem.Descrizione;
|
|
localDbCtx.Entry(currData).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetApp
|
|
.Add(updItem);
|
|
}
|
|
localDbCtx.SaveChanges();
|
|
done = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in UpdateApplicazioni:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return done;
|
|
}
|
|
|
|
public bool UpsertInstallazione(InstallazioneModel updItem)
|
|
{
|
|
bool done = false;
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
InstallazioneModel currData = localDbCtx
|
|
.DbSetInst
|
|
.Where(x => x.CodInst == updItem.CodInst)
|
|
.FirstOrDefault();
|
|
if (currData != null)
|
|
{
|
|
// aggiorno valori
|
|
currData.Descrizione = updItem.Descrizione;
|
|
currData.Cliente = updItem.Cliente;
|
|
currData.Contatto = updItem.Contatto;
|
|
currData.Email = updItem.Email;
|
|
localDbCtx.Entry(currData).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetInst
|
|
.Add(updItem);
|
|
}
|
|
localDbCtx.SaveChanges();
|
|
done = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in UpdateApplicazioni:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return done;
|
|
}
|
|
|
|
public bool UpsertLicenza(LicenzaModel updItem)
|
|
{
|
|
bool done = false;
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
LicenzaModel currData = localDbCtx
|
|
.DbSetLicenze
|
|
.Where(x => x.IdxLic == updItem.IdxLic)
|
|
.FirstOrDefault();
|
|
if (currData != null)
|
|
{
|
|
// storicizzo vecchia licenza in log
|
|
var newLogLic = new LogLicenzaModel()
|
|
{
|
|
Chiave = currData.Chiave,
|
|
CodApp = currData.CodApp,
|
|
CodInst = currData.CodInst,
|
|
Descrizione = currData.Descrizione,
|
|
IdxLic = currData.IdxLic,
|
|
Locked = true,
|
|
NumLicenze = currData.NumLicenze,
|
|
Scadenza = currData.Scadenza,
|
|
Tipo = currData.Tipo
|
|
};
|
|
|
|
localDbCtx
|
|
.DbSetLogLicenze
|
|
.Add(newLogLic);
|
|
|
|
// aggiorno valori licenza
|
|
currData.CodApp = updItem.CodApp;
|
|
currData.CodInst = updItem.CodInst;
|
|
currData.NumLicenze = updItem.NumLicenze;
|
|
currData.Descrizione = updItem.Descrizione;
|
|
currData.Chiave = updItem.ChiaveCalc;
|
|
currData.Scadenza = updItem.Scadenza;
|
|
currData.Locked = updItem.Locked;
|
|
currData.Payload = updItem.Payload;
|
|
currData.DataEnigma = updItem.DataEnigma;
|
|
currData.Enigma = updItem.Enigma;
|
|
localDbCtx.Entry(currData).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetLicenze
|
|
.Add(updItem);
|
|
}
|
|
localDbCtx.SaveChanges();
|
|
done = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in UpdateLicenze:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return done;
|
|
}
|
|
|
|
public bool UpsertLogLic(LogLicenzaModel updItem)
|
|
{
|
|
bool done = false;
|
|
using (LMDbContext localDbCtx = new LMDbContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
localDbCtx
|
|
.DbSetLogLicenze
|
|
.Add(updItem);
|
|
localDbCtx.SaveChanges();
|
|
done = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in UpdateApplicazioni:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return done;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |