Revisione modello dati + migration, bloccato invio dati al DB per revisione preliminare metodi

This commit is contained in:
Samuele Locatelli
2026-04-08 08:26:05 +02:00
parent db4f5d7d15
commit 1cdac18192
18 changed files with 191 additions and 142 deletions
@@ -85,22 +85,22 @@ namespace MP.Data.Repository.Utils
var existingRecords = await dbCtx
.DbSetStatsAggr
.Where(x => listRecords.Select(r => r.Hour).Contains(x.Hour) &&
listRecords.Select(r => r.Envir).Contains(x.Envir))
listRecords.Select(r => r.Destination).Contains(x.Destination))
.ToListAsync();
if (existingRecords.Count > 0)
{
var existingHours = existingRecords.Select(r => new { r.Hour, r.Envir }).ToHashSet();
var existingHours = existingRecords.Select(r => new { r.Hour, r.Destination }).ToHashSet();
var recordsToUpdate = listRecords.Where(r =>
existingHours.Contains(new { Hour = r.Hour, Envir = r.Envir })).ToList();
existingHours.Contains(new { Hour = r.Hour, Destination = r.Destination })).ToList();
var recordsToAdd = listRecords.Where(r =>
!existingHours.Contains(new { Hour = r.Hour, Envir = r.Envir })).ToList();
!existingHours.Contains(new { Hour = r.Hour, Destination = r.Destination })).ToList();
foreach (var updateRec in recordsToUpdate)
{
var existing = existingRecords.First(x => x.Hour == updateRec.Hour && x.Envir == updateRec.Envir);
var existing = existingRecords.First(x => x.Hour == updateRec.Hour && x.Destination == updateRec.Destination);
existing.RequestCount = updateRec.RequestCount;
existing.AvgDuration = updateRec.AvgDuration;
existing.MaxDuration = updateRec.MaxDuration;