384 lines
12 KiB
C#
384 lines
12 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MP.AppAuth.Models;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace MP.AppAuth.Controllers
|
|
{
|
|
public class MPController : IDisposable
|
|
{
|
|
#region Public Fields
|
|
|
|
public static MPController dbController;
|
|
|
|
#endregion Public Fields
|
|
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration;
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Public Constructors
|
|
|
|
public MPController(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
Log.Info("Avviata classe MpController");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Elenco Record x AnagCauSca
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AnagraficaCausaliScarto> AnagCauSca()
|
|
{
|
|
List<AnagraficaCausaliScarto> dbResult = new List<AnagraficaCausaliScarto>();
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetAnagCauSca
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Record x AnagClassiTempo
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AnagClassiTempo> AnagClassiTempo()
|
|
{
|
|
List<AnagClassiTempo> dbResult = new List<AnagClassiTempo>();
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetAnagClassiTempo
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Record x AnagraficaEventi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AnagraficaEventi> AnagEventi()
|
|
{
|
|
List<AnagraficaEventi> dbResult = new List<AnagraficaEventi>();
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetAnagEventi
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Record x AnagraficaIngressi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AnagraficaIngressi> AnagIngressi()
|
|
{
|
|
List<AnagraficaIngressi> dbResult = new List<AnagraficaIngressi>();
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetAnagIngressi
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delete Record AnagKeyValue
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool AnagKeyValuesDelete(string NomeVar)
|
|
{
|
|
bool fatto = false;
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var rec2del = localDbCtx
|
|
.DbSetAnagKeyValues
|
|
.Where(x => x.NomeVar == NomeVar)
|
|
.FirstOrDefault();
|
|
if (rec2del != null)
|
|
{
|
|
localDbCtx.Remove(rec2del);
|
|
var res = localDbCtx.SaveChanges();
|
|
fatto = res > 0;
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Record x AnagKeyValue
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AnagKeyValueModel> AnagKeyValuesGetAll()
|
|
{
|
|
List<AnagKeyValueModel> dbResult = new List<AnagKeyValueModel>();
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetAnagKeyValues
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Upsert AnagKeyValue
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool AnagKeyValuesUpsert(AnagKeyValueModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetAnagKeyValues
|
|
.Where(x => x.NomeVar == newRec.NomeVar)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
currRec.Descrizione = newRec.Descrizione;
|
|
currRec.ValInt = newRec.ValInt;
|
|
currRec.ValFloat = newRec.ValFloat;
|
|
currRec.ValString = newRec.ValString;
|
|
localDbCtx.Entry(currRec).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
localDbCtx.DbSetAnagKeyValues.Add(newRec);
|
|
}
|
|
var res = localDbCtx.SaveChanges();
|
|
fatto = res > 0;
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Record x AnagMicroStati
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AnagraficaMicroStati> AnagMicroStati()
|
|
{
|
|
List<AnagraficaMicroStati> dbResult = new List<AnagraficaMicroStati>();
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetAnagMicroStati
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Record x AnagraficaStati
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AnagraficaStati> AnagStati()
|
|
{
|
|
List<AnagraficaStati> dbResult = new List<AnagraficaStati>();
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetAnagStati
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delete Record Config
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool ConfigDelete(string Chiave)
|
|
{
|
|
bool fatto = false;
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var rec2del = localDbCtx
|
|
.DbSetConfig
|
|
.Where(x => x.Chiave == Chiave)
|
|
.FirstOrDefault();
|
|
if (rec2del != null)
|
|
{
|
|
localDbCtx.Remove(rec2del);
|
|
var res = localDbCtx.SaveChanges();
|
|
fatto = res > 0;
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Record x Config
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ConfigModel> ConfigGetAll()
|
|
{
|
|
List<ConfigModel> dbResult = new List<ConfigModel>();
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetConfig
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Upsert Config
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool ConfigUpsert(ConfigModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetConfig
|
|
.Where(x => x.Chiave == newRec.Chiave)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
currRec.Valore = newRec.Valore;
|
|
currRec.ValoreStd = newRec.ValoreStd;
|
|
currRec.Note = newRec.Note;
|
|
localDbCtx.Entry(currRec).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
localDbCtx.DbSetConfig.Add(newRec);
|
|
}
|
|
var res = localDbCtx.SaveChanges();
|
|
fatto = res > 0;
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (dbController != null)
|
|
{
|
|
// Clear database controller
|
|
dbController.Dispose();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Record x ListValues
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ListValues> ListValues()
|
|
{
|
|
List<ListValues> dbResult = new List<ListValues>();
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetListValue
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Record Macchine
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<MacchineModel> MacchineGetAll()
|
|
{
|
|
List<MacchineModel> dbResult = new List<MacchineModel>();
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetMacchine
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delete Record Vocabolario
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool VocabolarioDelete(VocabolarioModel currRec)
|
|
{
|
|
bool fatto = false;
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var rec2del = localDbCtx
|
|
.DbSetVocabolario
|
|
.Where(x => x.Lingua == currRec.Lingua && x.Lemma == currRec.Lemma)
|
|
.FirstOrDefault();
|
|
if (rec2del != null)
|
|
{
|
|
localDbCtx.Remove(rec2del);
|
|
var res = localDbCtx.SaveChanges();
|
|
fatto = res > 0;
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Record x VocabolarioModel
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<VocabolarioModel> VocabolarioGetAll()
|
|
{
|
|
List<VocabolarioModel> dbResult = new List<VocabolarioModel>();
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetVocabolario
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Upsert Vocabolario
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool VocabolarioUpsert(VocabolarioModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
using (MoonProContext localDbCtx = new MoonProContext(_configuration))
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetVocabolario
|
|
.Where(x => x.Lingua == newRec.Lingua && x.Lemma == newRec.Lemma)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
currRec.Traduzione = newRec.Traduzione;
|
|
localDbCtx.Entry(currRec).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
localDbCtx.DbSetVocabolario.Add(newRec);
|
|
}
|
|
var res = localDbCtx.SaveChanges();
|
|
fatto = res > 0;
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |