Update metodo controller x sync stato archiviato

This commit is contained in:
Samuele Locatelli
2024-07-17 10:21:13 +02:00
parent 1319496e52
commit 5f4e85df07
7 changed files with 79 additions and 13 deletions
@@ -1499,6 +1499,49 @@ namespace MagMan.Data.Tenant.Controllers
return numMod;
}
/// <summary>
/// Update record Project + refresh cache x info archived
/// </summary>
/// <param name="connString">Stringa connessione (variabile x cliente)</param>
/// <param name="newData">IDizionario ProdId / IsArchived da impostare</param>
/// <returns>Esito update</returns>
public bool ProjectUpdArchived(string connString, Dictionary<int, bool> newData)
{
bool fatto = false;
using (MagManContext dbCtx = new MagManContext(connString))
{
try
{
DateTime adesso = DateTime.Now;
foreach (var item in newData)
{
/*
* Ricerca:
* - DbId corrisponde e > 0...
* */
var currData = dbCtx
.DbSetProjects
.Where(x => (item.Key > 0 && x.ProjDbId == item.Key))
.FirstOrDefault();
if (currData != null)
{
currData.IsArchived = item.Value;
currData.DtLastAction = adesso;
dbCtx.Entry(currData).State = EntityState.Modified;
}
}
var done = dbCtx.SaveChanges();
// registro esito ok
fatto = done > 0;
}
catch (Exception exc)
{
Log.Error($"Eccezione in ProjectUpdArchived{Environment.NewLine}{exc}");
}
}
return fatto;
}
#endregion Public Methods
#region Private Fields
@@ -1322,6 +1322,31 @@ namespace MagMan.Data.Tenant.Services
return fatto;
}
/// <summary>
/// Update record Project + refresh cache x info archived
/// </summary>
/// <param name="nKey">Key di riferimento</param>
/// <param name="newData">IDizionario ProdId / IsArchived da impostare</param>
/// <returns>Bool aggiornamento</returns>
public async Task<bool> ProjectUpdArchived(int nKey, Dictionary<int, bool> newData)
{
bool fatto = false;
string cString = ConnString(nKey);
try
{
fatto = dbController.ProjectUpdArchived(cString, newData);
if (fatto)
{
await FlushRedisCache();
}
}
catch (Exception exc)
{
Log.Error($"Error during ProjectUpdArchived:{Environment.NewLine}{exc}");
}
return fatto;
}
/// <summary>
/// Converte il DTO in ItemModel
/// </summary>
+7 -9
View File
@@ -118,7 +118,7 @@ namespace MagMan.UI.Controllers
// in primis recupero codice chiave da token...
int nKey = await MTAdmService.MainKeyByToken(id);
// formato decodifica stringa DateTime
string format = "yyyyMMddHHmmss";
string format = "yyyyMMddHHmmss";
CultureInfo provider = CultureInfo.InvariantCulture;
DateTime dtRif = DateTime.Now;
try
@@ -147,6 +147,7 @@ namespace MagMan.UI.Controllers
[HttpPost("proj-arch-send/{id}")]
public async Task<bool> ProjArchivedSend(string id, [FromBody] RestPayload.ProjStatusData rawData)
{
// attenzione: si potrebbe dover verificare la data-ora modifica (per ogni record) x decidere update e/o
bool answ = false;
// verifico ci sia valore da processare
if (!string.IsNullOrEmpty(id) && rawData != null)
@@ -155,25 +156,22 @@ namespace MagMan.UI.Controllers
int nKey = await MTAdmService.MainKeyByToken(id);
if (nKey > 0)
{
#if false
// recupero il tipo di info comprese
if (rawData.ProjectProgress != null)
// processo update!
if (rawData.ProjStatusList != null)
{
var cRec = rawData.ProjectProgress;
try
{
answ = await TService.ProjectSetProgr(nKey, cRec.ProjCloudId, cRec.ProcTimeReal, cRec.ValAct, cRec.ValMax);
answ = await TService.ProjectUpdArchived(nKey, rawData.ProjStatusList);
}
catch (Exception exc)
{
Log.Error($"ProjectsController.upsert | Errore in fase salvataggio ProjectDTO{Environment.NewLine}{exc}");
Log.Error($"ProjectsController.ProjArchivedSend | Errore in fase update stato archived per {rawData.ProjStatusList.Count} rec{Environment.NewLine}{exc}");
}
// resetto cache redis
await MTAdmService.FlushRedisCache();
// broadcast update via redis, indico nKey x update puntuale
MService.QueUpdProj.sendMessage($"{nKey}");
}
#endif
}
}
}
return answ;
+1 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>1.0.2407.1709</Version>
<Version>1.0.2407.1710</Version>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>MagMan - Wood Warehouse Management System</i>
<h4>Versione: 1.0.2407.1709</h4>
<h4>Versione: 1.0.2407.1710</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
1.0.2407.1709
1.0.2407.1710
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.0.2407.1709</version>
<version>1.0.2407.1710</version>
<url>http://nexus.steamware.net/repository/SWS/MagMan/stable/0/MagMan.UI.zip</url>
<changelog>http://nexus.steamware.net/repository/SWS/MagMan/stable/0/ChangeLog.html</changelog>
<mandatory>false</mandatory>