update metodi gestione Progetti:

- ritorno ID creato/aggiornato
- check funzioni insert/update
- REST refresh x testing
This commit is contained in:
Samuele Locatelli
2024-02-29 08:47:58 +01:00
parent 944ae6126c
commit bd7a82d50f
9 changed files with 36 additions and 38 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ namespace MagMan.Core.DTO
/// <summary>
/// Data di schedulazione (prevista)
/// </summary>
public DateTime DtSchedule { get; set; } = DateTime.Today.AddMonths(3);
public DateTime DtSchedule { get; set; } = DateTime.MinValue;
/// <summary>
/// Data Inizio Produzione
@@ -884,28 +884,28 @@ namespace MagMan.Data.Tenant.Controllers
}
/// <summary>
/// Aggiunge/Modifica un record Project
///Upsert di un record Project
/// </summary>
/// <param name="connString">Stringa connessione (variabile x cliente)</param>
/// <param name="rec2upd">Record da aggiungere/aggiornare</param>
/// <returns></returns>
public bool ProjectUpdate(string connString, ProjModel rec2upd)
/// <returns>ID del progetto creato/aggiornato da usare come CloudId</returns>
public int ProjectUpsert(string connString, ProjModel rec2upd)
{
bool done = false;
int newId = 0;
using (MagManContext dbCtx = new MagManContext(connString))
{
try
{
/*
* Ricerca:
* - DbId corrisponde
* - Key + Id remoti corrispondono
* - DbId corrisponde e > 0...
* [[ RIMOSSO - Key + Id remoti corrispondono]]
* */
var currData = dbCtx
.DbSetProjects
.Where(x => (x.ProjDbId == rec2upd.ProjDbId) ||
(x.ProjExtDbId == rec2upd.ProjExtDbId && x.KeyNum == rec2upd.KeyNum) ||
(x.ProjExtId == rec2upd.ProjExtId && x.KeyNum == rec2upd.KeyNum))
.Where(x => (rec2upd.ProjDbId > 0 && x.ProjDbId == rec2upd.ProjDbId))
//.Where(x => (rec2upd.ProjDbId > 0 && x.ProjDbId == rec2upd.ProjDbId) ||
// ((x.ProjExtDbId == rec2upd.ProjExtDbId && x.KeyNum == rec2upd.KeyNum) && (x.ProjExtId == rec2upd.ProjExtId && x.KeyNum == rec2upd.KeyNum)))
.FirstOrDefault();
if (currData != null)
{
@@ -935,14 +935,15 @@ namespace MagMan.Data.Tenant.Controllers
.Add(rec2upd);
}
dbCtx.SaveChanges();
done = true;
// il mio ID è quello originale o appena creato post save...
newId = rec2upd.ProjDbId;
}
catch (Exception exc)
{
Log.Error($"Eccezione in ItemUpdate{Environment.NewLine}{exc}");
Log.Error($"Eccezione in ProjectUpsert{Environment.NewLine}{exc}");
}
}
return done;
return newId;
}
/// <summary>
+11 -10
View File
@@ -892,10 +892,11 @@ namespace MagMan.Data.Tenant.Services
{
ProjModel answ = new ProjModel()
{
MachineID = origItem.MachineCloudId,
KeyNum = origItem.KeyNum,
ProjDbId =origItem.ProjCloudId,
ProjExtDbId = origItem.ProjLocalId,
ProjExtId = origItem.ProjExtId,
MachineID = origItem.MachineCloudId,
KeyNum = origItem.KeyNum,
BTLFileName = origItem.BTLFileName,
PType = origItem.PType,
Machine = origItem.Machine,
@@ -1048,28 +1049,28 @@ namespace MagMan.Data.Tenant.Services
}
/// <summary>
/// Update record Item + refresh cache
/// Upsert record Item + refresh cache
/// </summary>
/// <param name="nKey">Key di riferimento</param>
/// <param name="currItem">Item interesato</param>
/// <returns></returns>
public async Task<bool> ProjectUpdate(int nKey, ProjModel currItem)
/// <returns>ID del progetto creato/aggiornato da usare come CloudId</returns>
public async Task<int> ProjectUpsert(int nKey, ProjModel currItem)
{
bool fatto = false;
int prjCloudId = 0;
string cString = ConnString(nKey);
try
{
fatto = dbController.ProjectUpdate(cString, currItem);
if (fatto)
prjCloudId = dbController.ProjectUpsert(cString, currItem);
if (prjCloudId > 0)
{
await FlushRedisCache();
}
}
catch (Exception exc)
{
Log.Error($"Error during ProjectUpdate:{Environment.NewLine}{exc}");
Log.Error($"Error during ProjectUpsert:{Environment.NewLine}{exc}");
}
return fatto;
return prjCloudId;
}
/// <summary>
+6 -10
View File
@@ -75,22 +75,21 @@ namespace MagMan.UI.Controllers
// in primis recupero codice chiave da token...
int nKey = await MTAdmService.MainKeyByToken(id);
var rawList = await TService.ProjectGetAll(nKey);
ListRecords=rawList.Select(x => TService.ProjectToDto(x)).ToList();
ListRecords = rawList.Select(x => TService.ProjectToDto(x)).ToList();
}
return ListRecords;
}
/// <summary>
/// Processa una chiamata POST per l'invio di un oggetto di aggiornamento progetto
/// Processa una chiamata POST per l'invio di un oggetto di upsert progetto
/// PUT: api/Inventory/upsert/00000000-0000-0000-0000-000000000000
/// </summary>
/// <param name="id">token comunicazione</param>
/// <returns></returns>
/// <returns>ID del progetto creato da usare come CloudId</returns>
[HttpPost("upsert/{id}")]
public async Task<string> upsert(string id, [FromBody] RestPayload.Projects rawData)
public async Task<int> upsert(string id, [FromBody] RestPayload.Projects rawData)
{
string answ = "ND";
bool fatto = false;
int answ = 0;
// verifico ci sia valore
if (!string.IsNullOrEmpty(id) && rawData != null && rawData.Project != null)
{
@@ -102,20 +101,17 @@ namespace MagMan.UI.Controllers
var currRec = TService.ProjectFromDto(rawData.Project);
try
{
await TService.ProjectUpdate(nKey, currRec);
fatto = true;
answ = await TService.ProjectUpsert(nKey, currRec);
}
catch (Exception exc)
{
Log.Error($"ProjectsController.upsert | Errore in fase salvataggio ProjectDTO{Environment.NewLine}{exc}");
fatto = false;
}
// resetto cache redis
await MTAdmService.FlushRedisCache();
}
}
answ = fatto ? "OK" : "NO";
return answ;
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>1.0.2402.2216</Version>
<Version>1.0.2402.2908</Version>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>MagMan - Wood Warehouse Management System</i>
<h4>Versione: 1.0.2402.2216</h4>
<h4>Versione: 1.0.2402.2908</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
1.0.2402.2216
1.0.2402.2908
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.0.2402.2216</version>
<version>1.0.2402.2908</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>