@@ -139,23 +141,34 @@
PersonaRif = Scheda.Responsabile,
Barcodes = Scheda.Articoli.ConvertAll(x => x.Barcode),
Scandeza = (ScadenzaEnum)Scheda.Scadenza,
- ParentActivityId = Scheda.Ispezione?.ActivityId
+ // Aggancia all'ispezione esistente sul server (evita di crearne una nuova a ogni invio).
+ ParentActivityId = SteupDataService.InspectionPageState.Ispezione.ActivityId
}
);
- if (apiResponse != null)
+ if (apiResponse == null)
{
- Scheda.ActivityId = apiResponse.ActivityIdScheda;
- SteupDataService.InspectionPageState.Ispezione.ActivityId = apiResponse.ActivityIdIspezione;
-
- await IspezioniService.UpdateActivityIdIspezioneAsync(Ispezione.CodMdep, Ispezione.Data,
- UserSession.User.Username, apiResponse.ActivityIdIspezione
- );
- await IspezioniService.UpdateActivityIdSchedaAsync(Scheda.Id, Scheda.ActivityId);
-
- // Notifica il genitore così il contatore "da inviare" del reparto si aggiorna.
- await OnSchedaModified.InvokeAsync(Scheda);
+ Snackbar.Add("Invio non riuscito. La scheda resta sul dispositivo, riprova.", Severity.Error);
+ return;
}
+
+ Scheda.ActivityId = apiResponse.ActivityIdScheda;
+ SteupDataService.InspectionPageState.Ispezione.ActivityId = apiResponse.ActivityIdIspezione;
+
+ await IspezioniService.UpdateActivityIdIspezioneAsync(Ispezione.CodMdep, Ispezione.Data,
+ UserSession.User.Username, apiResponse.ActivityIdIspezione
+ );
+ await IspezioniService.UpdateActivityIdSchedaAsync(Scheda.Id, Scheda.ActivityId);
+
+ // Notifica il genitore così il contatore "da inviare" del reparto si aggiorna.
+ await OnSchedaModified.InvokeAsync(Scheda);
+
+ Snackbar.Add("Scheda inviata", Severity.Success);
+ }
+ catch (Exception e)
+ {
+ Snackbar.Add("Invio non riuscito. La scheda resta sul dispositivo, riprova.", Severity.Error);
+ Logger.LogError(e, e.Message);
}
finally
{
@@ -176,12 +189,23 @@
var fileList = (await FileManager.GetInspectionFiles(Ispezione, Scheda.ImageNames))?
.Where(x => x.ToUpload).ToList();
- if (fileList == null) return;
+ if (fileList == null || fileList.Count == 0)
+ {
+ Snackbar.Add("Nessuna nuova foto da inviare", Severity.Info);
+ return;
+ }
foreach (var file in fileList)
{
await IntegrySteupService.UploadFile(Scheda.ActivityId!, file.FileBytes!, file.Name!);
}
+
+ Snackbar.Add(fileList.Count == 1 ? "Foto inviata" : $"{fileList.Count} foto inviate", Severity.Success);
+ }
+ catch (Exception e)
+ {
+ Snackbar.Add("Invio foto non riuscito, riprova.", Severity.Error);
+ Logger.LogError(e, e.Message);
}
finally
{
diff --git a/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor b/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor
index 75b8d5c..06cf54d 100644
--- a/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor
+++ b/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor
@@ -296,7 +296,9 @@
PersonaRif = Scheda.Responsabile,
Barcodes = Scheda.Articoli.ConvertAll(x => x.Barcode),
Scandeza = (ScadenzaEnum)Scheda.Scadenza,
- ParentActivityId = IsNew ? null : Scheda.Ispezione?.ActivityId
+ // Aggancia la scheda all'ispezione GIA esistente sul server (se sincronizzata),
+ // altrimenti null e il server la crea. Evita di creare una nuova ispezione a ogni salvataggio.
+ ParentActivityId = SteupDataService.InspectionPageState.Ispezione.ActivityId
}
);
}
@@ -353,6 +355,9 @@
await IspezioniService.UpdateActivityIdIspezioneAsync(CodMdep, Data,
UserSession.User.Username, apiResponse.ActivityIdIspezione
);
+ // Tiene in memoria l'ActivityId dell'ispezione: il prossimo salvataggio nella stessa
+ // sessione lo userà come ParentActivityId invece di creare una nuova ispezione.
+ SteupDataService.InspectionPageState.Ispezione.ActivityId = apiResponse.ActivityIdIspezione;
Scheda.ActivityId = apiResponse.ActivityIdScheda;
}
@@ -393,9 +398,12 @@
await IspezioniService.UpdateSchedaAsync(Scheda);
if (apiResponse != null)
+ {
await IspezioniService.UpdateActivityIdIspezioneAsync(CodMdep, Data,
UserSession.User.Username, apiResponse.ActivityIdIspezione
);
+ SteupDataService.InspectionPageState.Ispezione.ActivityId = apiResponse.ActivityIdIspezione;
+ }
}
private async Task UploadFile(Scheda scheda)