Completata pagina confronto AnagKeyVal, da estendere!

This commit is contained in:
Samuele Locatelli
2024-07-22 19:39:26 +02:00
parent 4885041e8e
commit 192dbfc88d
13 changed files with 476 additions and 103 deletions
+54 -1
View File
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Configuration;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using MP.AppAuth.Models;
using NLog;
using System;
@@ -42,6 +43,58 @@ namespace MP.AppAuth.Controllers
}
return dbResult;
}
/// <summary>
/// Elenco Record x 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>
/// 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 Config