From c80e6dbf480fe41210abb8015bf2574faedad592 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 24 Mar 2026 16:01:22 +0100 Subject: [PATCH] Fix gestione note offerta (inseribili dopo riga item) --- .../Repository/Sales/OfferRowRepository.cs | 40 +++++++++++++++---- Lux.UI/Components/Compo/OfferRowMan.razor | 38 +++++++++--------- Lux.UI/Components/Compo/OfferRowMan.razor.cs | 3 +- 3 files changed, 54 insertions(+), 27 deletions(-) diff --git a/EgwCoreLib.Lux.Data/Repository/Sales/OfferRowRepository.cs b/EgwCoreLib.Lux.Data/Repository/Sales/OfferRowRepository.cs index 3a45672..b53f0dd 100644 --- a/EgwCoreLib.Lux.Data/Repository/Sales/OfferRowRepository.cs +++ b/EgwCoreLib.Lux.Data/Repository/Sales/OfferRowRepository.cs @@ -19,9 +19,35 @@ namespace EgwCoreLib.Lux.Data.Repository.Sales public async Task 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 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; } } diff --git a/Lux.UI/Components/Compo/OfferRowMan.razor b/Lux.UI/Components/Compo/OfferRowMan.razor index f8a53a0..1674b3a 100644 --- a/Lux.UI/Components/Compo/OfferRowMan.razor +++ b/Lux.UI/Components/Compo/OfferRowMan.razor @@ -47,7 +47,7 @@ else
- +
} @@ -120,7 +120,7 @@ else { bool isBuy = (item.SellingItemID > 2 && item.SellingItemID < 5); - + @if (DisplayMode == DisplayMode.Preview) { @if (isBuy) @@ -141,27 +141,27 @@ else } else { - - - - @if (DisplayMode == DisplayMode.Edit) - { - if (CurrEditMode == EditMode.None) + + + + @if (DisplayMode == DisplayMode.Edit) { - - + if (CurrEditMode == EditMode.None) + { + + + } + else + { + if (EditRecord != null && EditRecord.OfferRowID == item.OfferRowID) + { + + } + } } else { - if (EditRecord != null && EditRecord.OfferRowID == item.OfferRowID) - { - - } - } - } - else - { - @item.RowNum + @item.RowNum } } diff --git a/Lux.UI/Components/Compo/OfferRowMan.razor.cs b/Lux.UI/Components/Compo/OfferRowMan.razor.cs index a352906..1efb16e 100644 --- a/Lux.UI/Components/Compo/OfferRowMan.razor.cs +++ b/Lux.UI/Components/Compo/OfferRowMan.razor.cs @@ -6,7 +6,6 @@ using EgwCoreLib.Lux.Data.DbModel.Config; using EgwCoreLib.Lux.Data.DbModel.Sales; using EgwCoreLib.Lux.Data.DbModel.Utils; using EgwCoreLib.Lux.Data.Domains; -using EgwCoreLib.Lux.Data.Services; using EgwCoreLib.Lux.Data.Services.Config; using EgwCoreLib.Lux.Data.Services.General; using EgwCoreLib.Lux.Data.Services.Items; @@ -418,6 +417,8 @@ namespace Lux.UI.Components.Compo #region Private Methods + private string noteCss => EditRecord == null ? "btn-success" : "btn-primary bg-gradient"; + /// /// Effettua vera richiesta della BOM ///