Fix gestione note offerta (inseribili dopo riga item)

This commit is contained in:
Samuele Locatelli
2026-03-24 16:01:22 +01:00
parent c071537424
commit c80e6dbf48
3 changed files with 54 additions and 27 deletions
@@ -19,9 +19,35 @@ namespace EgwCoreLib.Lux.Data.Repository.Sales
public async Task<bool> AddAsync(OfferRowModel entity)
{
await using var dbCtx = await CreateContextAsync();
await dbCtx.DbSetOfferRow.AddAsync(entity);
return await dbCtx.SaveChangesAsync() > 0;
await using var dbCtx = await CreateContextAsync(); await using var tx = await dbCtx.Database.BeginTransactionAsync();
try
{
// SE ci fossero righe di indice pari o superiore le deve spostare...
// 2. Recupero i record successivi da shiftare
var list2Move = await dbCtx.DbSetOfferRow
.Where(x => x.OfferID == entity.OfferID && x.RowNum >= entity.RowNum)
.ToListAsync();
// aggiungo record
await dbCtx.DbSetOfferRow.AddAsync(entity);
foreach (var item in list2Move)
{
item.RowNum++;
dbCtx.Entry(item).State = EntityState.Modified;
}
bool done = await dbCtx.SaveChangesAsync() > 0;
if (done)
await tx.CommitAsync();
return done;
}
catch
{
await tx.RollbackAsync();
throw;
}
}
public async Task<bool> DeleteAsync(OfferRowModel entity)
@@ -57,13 +83,13 @@ namespace EgwCoreLib.Lux.Data.Repository.Sales
bool done = await dbCtx.SaveChangesAsync() > 0;
if (done)
tx.Commit();
await tx.CommitAsync();
return done;
}
catch
{
tx.Rollback();
await tx.RollbackAsync();
throw;
}
}
@@ -125,13 +151,13 @@ namespace EgwCoreLib.Lux.Data.Repository.Sales
bool done = await dbCtx.SaveChangesAsync() > 0;
if (done)
tx.Commit();
await tx.CommitAsync();
return done;
}
catch
{
tx.Rollback();
await tx.RollbackAsync();
throw;
}
}