From f6642e7a2770282f884002c4d8c7f151ab33c6dc Mon Sep 17 00:00:00 2001 From: Marco Audiffredi Date: Tue, 16 Jul 2024 17:32:36 +0200 Subject: [PATCH] PIMODGIR: CANCELLAZIONE PRIMA DI INSERIMENTO --- Controllers/ModificaGiroController.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Controllers/ModificaGiroController.cs b/Controllers/ModificaGiroController.cs index f6831ab..f9273d8 100644 --- a/Controllers/ModificaGiroController.cs +++ b/Controllers/ModificaGiroController.cs @@ -30,6 +30,20 @@ namespace ApiSoftway.Controllers //string usr = getClaimValueByToken(token, "codice"); try { + + //step 0: se esiste un record con quel seriale, prima cancello e poi inserisco di nuovo + _modgir = _modgiri_context.Mod; + List lst = _modgir.Where(t => t.Piserial.Equals(model.Piserial)).ToList(); + foreach (Modgir item in lst) + { + using (var transaction = _modgiri_context.Database.BeginTransaction()) + { + _modgiri_context.Entry(item).State = EntityState.Deleted; + await _modgiri_context.SaveChangesAsync(); + transaction.Commit(); + } + } + //step 1 : calcolo il nuovo seriale _modgir = _modgiri_context.Mod; var ser = await _modgir.Take(1).OrderByDescending(t => t.Piprogre).ToListAsync();