From e65822ceb566f11fec3821e93662d3f9e4de7f7a Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sat, 30 May 2026 10:20:17 +0200 Subject: [PATCH] Fix delete dossier sistemato... --- MP.Data/Controllers/MpSpecController.cs | 29 ++++++++---------------- MP.SPEC/Components/ListDossiers.razor | 2 +- MP.SPEC/Components/ListDossiers.razor.cs | 7 +++--- MP.SPEC/Data/MpDataService.cs | 15 ++++++------ 4 files changed, 21 insertions(+), 32 deletions(-) diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs index 873afa7f..83a95c6c 100644 --- a/MP.Data/Controllers/MpSpecController.cs +++ b/MP.Data/Controllers/MpSpecController.cs @@ -735,29 +735,18 @@ namespace MP.Data.Controllers /// /// record dossier da eliminare /// - public async Task DossiersDeleteRecord(DossierModel currRec) + public async Task DossiersDeleteRecordAsync(DossierModel currRec) { - bool answ = false; - using (var dbCtx = new MoonPro_FluxContext(_configuration)) - { - try - { - var currVal = dbCtx + using var dbCtx = new MoonPro_FluxContext(_configuration); + var currVal = await dbCtx .DbSetDossiers .Where(x => x.IdxDossier == currRec.IdxDossier) - .FirstOrDefault(); - dbCtx - .DbSetDossiers - .Remove(currVal); - await dbCtx.SaveChangesAsync(); - answ = true; - } - catch (Exception exc) - { - Log.Error($"Eccezione durante DossiersDeleteRecord{Environment.NewLine}{exc}"); - } - } - return answ; + .FirstOrDefaultAsync(); + dbCtx + .DbSetDossiers + .Remove(currVal); + + return await dbCtx.SaveChangesAsync() > 0; } /// diff --git a/MP.SPEC/Components/ListDossiers.razor b/MP.SPEC/Components/ListDossiers.razor index a497db87..ee07e0f6 100644 --- a/MP.SPEC/Components/ListDossiers.razor +++ b/MP.SPEC/Components/ListDossiers.razor @@ -261,7 +261,7 @@ else @if (isEditing == false) { - + } else { diff --git a/MP.SPEC/Components/ListDossiers.razor.cs b/MP.SPEC/Components/ListDossiers.razor.cs index 31d1b9b3..4ec778d3 100644 --- a/MP.SPEC/Components/ListDossiers.razor.cs +++ b/MP.SPEC/Components/ListDossiers.razor.cs @@ -146,16 +146,15 @@ namespace MP.SPEC.Components /// /// /// - protected async Task deleteRecord(DossierModel selRec) + protected async Task DoDelete(DossierModel selRec) { if (!await JSRuntime.InvokeAsync("confirm", "Eliminazione Dossier: sei sicuro di voler procedere?")) return; - await Task.Delay(1); - var done = await MDService.DossiersDeleteRecord(selRec); + + var done = await MDService.DossiersDeleteRecordAsync(selRec); currRecord = null; await ReloadData(true); visualizzaFlux = true; - await Task.Delay(1); } protected async Task editRecord(FluxLogDTO selRec) diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 0cf62585..d5b0051d 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -548,17 +548,18 @@ namespace MP.SPEC.Data /// /// record dossier da eliminare /// - public async Task DossiersDeleteRecord(DossierModel selRecord) + public async Task DossiersDeleteRecordAsync(DossierModel selRecord) { - using var activity = ActivitySource.StartActivity("DossiersDeleteRecord"); + using var activity = ActivitySource.StartActivity("DossiersDeleteRecordAsync"); bool result = false; - result = await dbController.DossiersDeleteRecord(selRecord); + result = await dbController.DossiersDeleteRecordAsync(selRecord); // elimino cache redis... - RedisValue pattern = new RedisValue($"{Utils.redisDossByMac}:*"); - bool answ = await ExecFlushRedisPatternAsync(pattern); - activity?.SetTag("data.source", "DB+REDIS"); + //RedisValue pattern = new RedisValue($"{Utils.redisDossByMac}:*"); + //bool answ = await ExecFlushRedisPatternAsync(pattern); + await FlushCacheByTagAsync(Utils.redisDossByMac); + activity?.SetTag("data.source", "DB"); activity?.Stop(); - LogTrace($"DossiersDeleteRecord | IdxMacchina {selRecord.IdxMacchina} | DtRif {selRecord.DtRif} | IdxODL {selRecord.IdxODL} | {activity?.Duration.TotalMilliseconds}ms"); + LogTrace($"DossiersDeleteRecordAsync | IdxMacchina {selRecord.IdxMacchina} | DtRif {selRecord.DtRif} | IdxODL {selRecord.IdxODL} | {activity?.Duration.TotalMilliseconds}ms"); return result; }