Aggiunta gestione microstatomacchina
This commit is contained in:
@@ -34,6 +34,13 @@ namespace MP.Data.Repository.IOC
|
||||
/// <returns></returns>
|
||||
Task<bool> EvListMicroStatoInsertAsync(MicroStatoMacchinaModel newRecMsm, EventListModel newRecEv);
|
||||
|
||||
/// <summary>
|
||||
/// Aggiornamento record Microstato macchina
|
||||
/// </summary>
|
||||
/// <param name="newRec"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> MicroStatoMacchinaUpsertAsync(MicroStatoMacchinaModel newRec);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -102,9 +102,9 @@ namespace MP.Data.Repository.IOC
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> EvListMicroStatoInsertAsync(MicroStatoMacchinaModel newRecMsm, EventListModel newRecEv)
|
||||
{
|
||||
// eseguo in transazione...
|
||||
await using var dbCtx = await CreateContextAsync();
|
||||
await using var tx = await dbCtx.Database.BeginTransactionAsync(IsolationLevel.ReadCommitted);
|
||||
//// eseguo in transazione...
|
||||
//await using var tx = await dbCtx.Database.BeginTransactionAsync(IsolationLevel.ReadCommitted);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -132,17 +132,48 @@ namespace MP.Data.Repository.IOC
|
||||
|
||||
// EF Core 8 raggruppa automaticamente INSERT/UPDATE in un batch
|
||||
var rowsAffected = await dbCtx.SaveChangesAsync();
|
||||
await tx.CommitAsync();
|
||||
//await tx.CommitAsync();
|
||||
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
await tx.RollbackAsync();
|
||||
//await tx.RollbackAsync();
|
||||
// Log dettagliato errore
|
||||
Log.Error(ex, $"Errore in EvListMicroStatoInsertAsync: {newRecEv.IdxMacchina}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> MicroStatoMacchinaUpsertAsync(MicroStatoMacchinaModel newRec)
|
||||
{
|
||||
bool fatto = false;
|
||||
using var dbCtx = new MoonProContext(options);
|
||||
|
||||
var actRec = await dbCtx
|
||||
.DbSetMicroStatoMacc
|
||||
.Where(x => x.IdxMacchina == newRec.IdxMacchina)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync();
|
||||
if (actRec == null)
|
||||
{
|
||||
dbCtx
|
||||
.DbSetMicroStatoMacc
|
||||
.Add(newRec);
|
||||
}
|
||||
else
|
||||
{
|
||||
actRec.IdxMicroStato = newRec.IdxMicroStato;
|
||||
actRec.InizioStato = newRec.InizioStato;
|
||||
actRec.Value = newRec.Value;
|
||||
|
||||
dbCtx.Entry(actRec).State = EntityState.Modified;
|
||||
}
|
||||
fatto = await dbCtx.SaveChangesAsync() > 0;
|
||||
|
||||
return fatto;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
Reference in New Issue
Block a user