229 lines
7.8 KiB
C#
229 lines
7.8 KiB
C#
using LiMan.GLS.DatabaseModels;
|
|
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.GLS.Controllers
|
|
{
|
|
public class LicManController : IDisposable
|
|
{
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration;
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Public Constructors
|
|
|
|
public LicManController(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
public bool DbForceMigrate()
|
|
{
|
|
bool answ = false;
|
|
using (LicManContext localDbCtx = new LicManContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
localDbCtx.DbForceMigrate();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in DbForceMigrate{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// Clear database context
|
|
//Log.Info("Dispose di GWMSController");
|
|
}
|
|
|
|
public List<AnagApplicazioni> GetApplicazioni()
|
|
{
|
|
List<AnagApplicazioni> dbResult = new List<AnagApplicazioni>();
|
|
using (LicManContext localDbCtx = new LicManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetApplicazioni
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<AnagInstallazioni> GetInstallazioni()
|
|
{
|
|
List<AnagInstallazioni> dbResult = new List<AnagInstallazioni>();
|
|
using (LicManContext localDbCtx = new LicManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetInstallazioni
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<LicenzeAttive> GetLicenze()
|
|
{
|
|
List<LicenzeAttive> dbResult = new List<LicenzeAttive>();
|
|
using (LicManContext localDbCtx = new LicManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetLicenzeAttive
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<LicenzeAttive> GetLicenzeFilt(bool OnlyActive, bool OnlyUnlock, string Appl, string Inst)
|
|
{
|
|
List<LicenzeAttive> dbResult = new List<LicenzeAttive>();
|
|
using (LicManContext localDbCtx = new LicManContext(_configuration))
|
|
{
|
|
DateTime oggi = DateTime.Today;
|
|
dbResult = localDbCtx
|
|
.DbSetLicenzeAttive
|
|
.Where(x => (x.Applicativo == Appl || string.IsNullOrEmpty(Appl)) && (x.Installazione == Inst || string.IsNullOrEmpty(Inst)) && (!OnlyActive || x.Scadenza > oggi) && (!OnlyUnlock || x.Locked == false))
|
|
.Include(a => a.ApplicativoNavigation)
|
|
.Include(i => i.InstallazioneNavigation)
|
|
.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 (LicManContext localDbCtx = new LicManContext(_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 UpdateApplicazioni(AnagApplicazioni updItem)
|
|
{
|
|
bool done = false;
|
|
using (LicManContext localDbCtx = new LicManContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
AnagApplicazioni currData = localDbCtx
|
|
.DbSetApplicazioni
|
|
.Where(x => x.Applicativo == updItem.Applicativo)
|
|
.FirstOrDefault();
|
|
if (currData != null)
|
|
{
|
|
// aggiorno valori
|
|
currData.Descrizione = updItem.Descrizione;
|
|
localDbCtx.Entry(currData).State = EntityState.Modified;
|
|
localDbCtx.SaveChanges();
|
|
}
|
|
done = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in UpdateApplicazione:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return done;
|
|
}
|
|
|
|
public bool UpdateInstallazioni(AnagInstallazioni updItem)
|
|
{
|
|
bool done = false;
|
|
using (LicManContext localDbCtx = new LicManContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
AnagInstallazioni currData = localDbCtx
|
|
.DbSetInstallazioni
|
|
.Where(x => x.Installazione == updItem.Installazione)
|
|
.FirstOrDefault();
|
|
if (currData != null)
|
|
{
|
|
// aggiorno valori
|
|
currData.Contatto = updItem.Contatto;
|
|
currData.Descrizione = updItem.Descrizione;
|
|
currData.Email = updItem.Email;
|
|
localDbCtx.Entry(currData).State = EntityState.Modified;
|
|
localDbCtx.SaveChanges();
|
|
}
|
|
done = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in UpdateInstallazione:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return done;
|
|
}
|
|
|
|
public bool UpdateLicenze(LicenzeAttive updItem)
|
|
{
|
|
bool done = false;
|
|
using (LicManContext localDbCtx = new LicManContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
LicenzeAttive currData = localDbCtx
|
|
.DbSetLicenzeAttive
|
|
.Where(x => x.IdxLic == updItem.IdxLic)
|
|
.FirstOrDefault();
|
|
if (currData != null)
|
|
{
|
|
// aggiorno valori
|
|
currData.Applicativo = updItem.Applicativo;
|
|
currData.Installazione = updItem.Installazione;
|
|
currData.NumLicenze = updItem.NumLicenze;
|
|
currData.Descrizione = updItem.Descrizione;
|
|
currData.Licenza = updItem.Licenza;
|
|
currData.Locked = updItem.Locked;
|
|
currData.Scadenza = updItem.Scadenza;
|
|
localDbCtx.Entry(currData).State = EntityState.Modified;
|
|
localDbCtx.SaveChanges();
|
|
}
|
|
done = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in UpdateLicenza:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return done;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |