Fix gestione allegati e creato metodo di esportazione log
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
@using SteUp.Shared.Components.Layout
|
||||
@using System.Data.Common
|
||||
@using Microsoft.Extensions.Logging
|
||||
@using SteUp.Shared.Components.Layout
|
||||
@using SteUp.Shared.Components.Layout.Overlay
|
||||
@using SteUp.Shared.Components.Layout.Spinner
|
||||
@using SteUp.Shared.Components.SingleElements.Card.ModalForm
|
||||
@@ -13,10 +15,11 @@
|
||||
@inject INetworkService NetworkService
|
||||
@inject IDialogService Dialog
|
||||
@inject IIntegryApiService IntegryApiService
|
||||
@inject IAttachedService AttachedService
|
||||
@inject IFileManager FileManager
|
||||
@inject IIspezioniService IspezioniService
|
||||
@inject IIntegrySteupService IntegrySteupService
|
||||
@inject OnScannerService OnScannerService
|
||||
@inject ILogger<ModalFormScheda> Logger
|
||||
|
||||
<MudDialog Class="customDialog-form">
|
||||
<DialogContent>
|
||||
@@ -75,7 +78,7 @@
|
||||
}
|
||||
<MudCardContent Class="image_card">
|
||||
<MudText Typo="Typo.subtitle1"><b>@item.p.Name</b></MudText>
|
||||
@if (IsNew)
|
||||
@if (item.p.ToUpload)
|
||||
{
|
||||
<MudIconButton Variant="Variant.Outlined"
|
||||
Icon="@Icons.Material.Rounded.Close"
|
||||
@@ -236,7 +239,7 @@
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var fileList = await AttachedService.GetInspectionFiles(
|
||||
var fileList = await FileManager.GetInspectionFiles(
|
||||
new Ispezione
|
||||
{
|
||||
CodMdep = CodMdep,
|
||||
@@ -285,17 +288,19 @@
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
var message = e.Message;
|
||||
|
||||
await Dialog.ShowError(e.Message);
|
||||
Logger.LogError(e, message);
|
||||
Console.WriteLine(message);
|
||||
await Dialog.ShowError(message);
|
||||
}
|
||||
|
||||
if (IsNew) await NewSave(apiResponse);
|
||||
else await Update(apiResponse);
|
||||
|
||||
if (Scheda.ActivityId.IsValorized()) await UploadFile(Scheda.ActivityId!);
|
||||
if (Scheda.ActivityId.IsValorized()) await UploadFile(Scheda);
|
||||
|
||||
await AttachedService.CleanTempStorageAsync();
|
||||
await FileManager.CleanTempStorageAsync();
|
||||
|
||||
SuccessAnimation = true;
|
||||
StateHasChanged();
|
||||
@@ -311,7 +316,7 @@
|
||||
{
|
||||
foreach (var attached in AttachedList!)
|
||||
{
|
||||
var fileNameAdded = await AttachedService.SaveInspectionFile(
|
||||
var fileNameAdded = await FileManager.SaveInspectionFile(
|
||||
new Ispezione
|
||||
{
|
||||
CodMdep = CodMdep,
|
||||
@@ -354,7 +359,7 @@
|
||||
|
||||
if (!attached.ToRemove)
|
||||
{
|
||||
var fileNameAdded = await AttachedService.SaveInspectionFile(
|
||||
var fileNameAdded = await FileManager.SaveInspectionFile(
|
||||
ispezione,
|
||||
attached.FileBytes!,
|
||||
attached.Name!
|
||||
@@ -365,7 +370,7 @@
|
||||
Scheda.ImageNames.Add(fileNameAdded);
|
||||
}
|
||||
else
|
||||
_ = AttachedService.RemoveInspectionFile(ispezione, attached.Name!);
|
||||
_ = FileManager.RemoveInspectionFile(ispezione, attached.Name!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,7 +383,7 @@
|
||||
);
|
||||
}
|
||||
|
||||
private async Task UploadFile(string activityId)
|
||||
private async Task UploadFile(Scheda scheda)
|
||||
{
|
||||
if (AttachedList.IsNullOrEmpty()) return;
|
||||
|
||||
@@ -393,16 +398,23 @@
|
||||
{
|
||||
if (file.FileBytes == null || file.Name == null) continue;
|
||||
|
||||
await IntegrySteupService.UploadFile(activityId, file.FileBytes, file.Name);
|
||||
await AttachedService.MoveInspectionFileFromToUploadToFinal(ispezione, file.Name);
|
||||
await IntegrySteupService.UploadFile(scheda.ActivityId!, file.FileBytes, file.Name);
|
||||
var newPath = await FileManager.MoveInspectionFileFromToUploadToFinal(ispezione, file.Name);
|
||||
if (newPath == null) continue;
|
||||
|
||||
var filePathToRemove = FileManager.GetFileToUploadDir(ispezione, file.Name);
|
||||
scheda.ImageNames!.Remove(filePathToRemove);
|
||||
scheda.ImageNames.Add(newPath);
|
||||
}
|
||||
|
||||
await IspezioniService.UpdateFileListSchedaAsync(scheda.Id, scheda.ImageNames);
|
||||
}
|
||||
|
||||
private async Task Cancel()
|
||||
{
|
||||
if (await CheckSavePreAction())
|
||||
{
|
||||
await AttachedService.CleanTempStorageAsync();
|
||||
await FileManager.CleanTempStorageAsync();
|
||||
DisposeMessage();
|
||||
MudDialog.Cancel();
|
||||
}
|
||||
@@ -500,7 +512,7 @@
|
||||
var a = attachedList[i];
|
||||
if (a.FileBytes is null || a.Name is null) continue;
|
||||
|
||||
var (origUrl, thumbUrl) = await AttachedService.SaveAndCreateThumbAsync(a.FileBytes, a.Name);
|
||||
var (origUrl, thumbUrl) = await FileManager.SaveAndCreateThumbAsync(a.FileBytes, a.Name);
|
||||
|
||||
await InvokeAsync(() =>
|
||||
{
|
||||
@@ -557,7 +569,7 @@
|
||||
TextLoading = null;
|
||||
StateHasChanged();
|
||||
|
||||
OnError(e.Message);
|
||||
OnError(e, e.Message);
|
||||
});
|
||||
|
||||
return;
|
||||
@@ -670,7 +682,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
OnError("Nessun articolo trovato");
|
||||
OnError(null, "Nessun articolo trovato");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -684,18 +696,19 @@
|
||||
StateHasChanged();
|
||||
});
|
||||
|
||||
OnError(e.Message);
|
||||
OnError(e, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnErrorScan(string? value) => OnError(value);
|
||||
private void OnErrorScan(string? value) => OnError(new Exception(value), value);
|
||||
|
||||
#endregion
|
||||
|
||||
private void OnError(string? errorMessage)
|
||||
private void OnError(Exception? e, string? errorMessage)
|
||||
{
|
||||
if (e != null) Logger.LogError(e, errorMessage);
|
||||
if (errorMessage == null) return;
|
||||
|
||||
|
||||
_ = Dialog.ShowError(errorMessage);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user