Finora la foto si poteva togliere solo prima di salvare la scheda. - La X compare su tutte le foto (non in sola lettura, non mentre la foto e' ancora in elaborazione). L'eliminazione avviene al salvataggio: uscendo senza salvare le foto restano. - Una foto gia' inviata si toglie prima dal server (nuovo endpoint steup/removeAttachment), poi dal dispositivo e da Scheda.ImageNames. Senza rete la X avvisa e non la toglie; se il server non conferma al salvataggio la foto resta ovunque e compare un avviso. - Una foto salvata ma non ancora inviata si elimina dal dispositivo (con la rete si prova anche a toglierla dal server, senza bloccare). - Togliere una foto salvata non la cancellava mai: il flag ToRemove finiva su un elemento appena rimosso dall'elenco. Ora le foto tolte stanno in una lista a parte fino al salvataggio; ToRemove e' stato eliminato. - FileManager.GetInspectionFiles: le foto in /toUpload si filtravano per nome, ma ImageNames contiene il percorso completo, quindi quelle salvate senza rete non ricomparivano mai riaprendo la scheda. Ora si accetta sia il percorso sia il nome, e il DTO porta anche i byte del file per l'invio. Richiede i Servizi con steup/removeAttachment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
3.7 KiB
C#
95 lines
3.7 KiB
C#
using System.Net.Http.Headers;
|
|
using IntegryApiClient.Core.Domain.RestClient.Contacts;
|
|
using SteUp.Shared.Core.Dto;
|
|
using SteUp.Shared.Core.Interface.IntegryApi;
|
|
|
|
namespace SteUp.Shared.Core.Services;
|
|
|
|
public class IntegrySteupService(IIntegryApiRestClient integryApiRestClient) : IIntegrySteupService
|
|
{
|
|
private const string BaseRequest = "steup";
|
|
|
|
#region Retrieve
|
|
|
|
public Task<List<PuntoVenditaDto>> RetrievePuntiVendita() =>
|
|
integryApiRestClient.AuthorizedGet<List<PuntoVenditaDto>>($"{BaseRequest}/retrievePuntiVendita")!;
|
|
|
|
public Task<List<JtbFasiDto>> RetrieveReparti() =>
|
|
integryApiRestClient.AuthorizedGet<List<JtbFasiDto>>($"{BaseRequest}/retrieveReparti")!;
|
|
|
|
public Task<List<ActivityTypeDto>> RetrieveActivityType() =>
|
|
integryApiRestClient.AuthorizedGet<List<ActivityTypeDto>>($"{BaseRequest}/retrieveActivityType")!;
|
|
|
|
public Task<List<ArticoliInGrigliaDto>?> RetrieveGrigliaPlu(RetrieveGrigliaPluRequestDto request) =>
|
|
integryApiRestClient.AuthorizedPost<List<ArticoliInGrigliaDto>?>($"{BaseRequest}/retrieveGrigliaPlu", request);
|
|
|
|
public Task<ArticoliInGrigliaDto?> RetrieveArtFromBarcode(string barcode) =>
|
|
integryApiRestClient.AuthorizedGet<ArticoliInGrigliaDto?>(
|
|
$"{BaseRequest}/retrieveArtFromBarcode",
|
|
new Dictionary<string, object?>
|
|
{
|
|
{ "barcode", barcode }
|
|
}
|
|
);
|
|
|
|
public Task<List<StbActivityDto>?> RetrieveStatoIspezioni(RetrieveStatoIspezioniRequestDto request) =>
|
|
integryApiRestClient.AuthorizedPost<List<StbActivityDto>?>($"{BaseRequest}/retrieveStatoIspezioni", request);
|
|
|
|
#endregion
|
|
|
|
#region Save
|
|
|
|
public Task<SaveSchedaResponseDto?> SaveScheda(SaveRequestDto request) =>
|
|
integryApiRestClient.AuthorizedPost<SaveSchedaResponseDto?>($"{BaseRequest}/saveScheda", request);
|
|
|
|
public Task<SaveSchedaResponseDto?> SaveMultipleSchede(List<SaveRequestDto> request) =>
|
|
integryApiRestClient.AuthorizedPost<SaveSchedaResponseDto?>($"{BaseRequest}/saveMultipleSchede", request);
|
|
|
|
public Task CompleteInspection(string activityId) =>
|
|
integryApiRestClient.AuthorizedPost<object>(
|
|
$"{BaseRequest}/complete",
|
|
new object(),
|
|
new Dictionary<string, object>
|
|
{
|
|
{ "activityId", activityId }
|
|
}!
|
|
);
|
|
|
|
#endregion
|
|
|
|
public async Task UploadFile(string activityId, byte[] file, string fileName)
|
|
{
|
|
var queryParams = new Dictionary<string, object> { { "activityId", activityId } };
|
|
|
|
var content = new MultipartFormDataContent();
|
|
var fileContent = new ByteArrayContent(file);
|
|
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");
|
|
content.Add(fileContent, "file", fileName);
|
|
|
|
await integryApiRestClient.Post<object>($"{BaseRequest}/uploadAttachment", content, queryParams!);
|
|
content.Dispose();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Toglie un allegato dalla scheda. Il server lo riconosce dal nome con cui
|
|
/// è stato caricato da <see cref="UploadFile"/>.
|
|
/// </summary>
|
|
public Task RemoveFile(string activityId, string fileName) =>
|
|
integryApiRestClient.AuthorizedGet<object>(
|
|
$"{BaseRequest}/removeAttachment",
|
|
new Dictionary<string, object?>
|
|
{
|
|
{ "activityId", activityId },
|
|
{ "fileName", fileName }
|
|
}
|
|
);
|
|
|
|
public Task DeleteScheda(string activityId) =>
|
|
integryApiRestClient.AuthorizedGet<object>(
|
|
$"{BaseRequest}/deleteScheda",
|
|
new Dictionary<string, object?>
|
|
{
|
|
{ "activityId", activityId }
|
|
}
|
|
);
|
|
} |