Merge branch 'develop' into feature/Firebase

# Conflicts:
#	salesbook.Shared/Components/Pages/Home.razor
This commit is contained in:
2025-09-08 12:22:24 +02:00
69 changed files with 2364 additions and 369 deletions

View File

@@ -57,9 +57,53 @@ public class AttachedService : IAttachedService
Name = file.FileName,
Path = file.FullPath,
MimeType = file.ContentType,
DimensionBytes= ms.Length,
FileContent = ms.ToArray(),
DimensionBytes = ms.Length,
FileBytes = ms.ToArray(),
Type = type
};
}
private static async Task<string?> SaveToTempStorage(Stream file, string fileName)
{
var cacheDirectory = FileSystem.CacheDirectory;
var targetDirectory = Path.Combine(cacheDirectory, "file");
if (!Directory.Exists(targetDirectory)) Directory.CreateDirectory(targetDirectory);
var tempFilePath = Path.Combine(targetDirectory, fileName + ".temp");
var filePath = Path.Combine(targetDirectory, fileName);
if (File.Exists(filePath)) return filePath;
try
{
await using var fileStream =
new FileStream(tempFilePath, FileMode.Create, FileAccess.Write, FileShare.None);
await file.CopyToAsync(fileStream);
File.Move(tempFilePath, filePath);
}
catch (Exception e)
{
Console.WriteLine($"Errore durante il salvataggio dello stream: {e.Message}");
return null;
}
finally
{
if (File.Exists(tempFilePath)) File.Delete(tempFilePath);
}
return filePath;
}
public async Task OpenFile(Stream file, string fileName)
{
var filePath = await SaveToTempStorage(file, fileName);
if (filePath is null) return;
await Launcher.OpenAsync(new OpenFileRequest
{
File = new ReadOnlyFile(filePath)
});
}
}

View File

@@ -22,6 +22,7 @@ public class LocalDbService
_connection.CreateTableAsync<VtbDest>();
_connection.CreateTableAsync<StbActivityResult>();
_connection.CreateTableAsync<StbActivityType>();
_connection.CreateTableAsync<SrlActivityTypeUser>();
_connection.CreateTableAsync<StbUser>();
_connection.CreateTableAsync<VtbTipi>();
_connection.CreateTableAsync<Nazioni>();
@@ -33,12 +34,14 @@ public class LocalDbService
{
await _connection.ExecuteAsync("DROP TABLE IF EXISTS stb_activity_result;");
await _connection.ExecuteAsync("DROP TABLE IF EXISTS stb_activity_type;");
await _connection.ExecuteAsync("DROP TABLE IF EXISTS srl_activity_type_user;");
await _connection.ExecuteAsync("DROP TABLE IF EXISTS stb_user;");
await _connection.ExecuteAsync("DROP TABLE IF EXISTS vtb_tipi;");
await _connection.ExecuteAsync("DROP TABLE IF EXISTS nazioni;");
await _connection.CreateTableAsync<StbActivityResult>();
await _connection.CreateTableAsync<StbActivityType>();
await _connection.CreateTableAsync<SrlActivityTypeUser>();
await _connection.CreateTableAsync<StbUser>();
await _connection.CreateTableAsync<VtbTipi>();
await _connection.CreateTableAsync<Nazioni>();

View File

@@ -1,21 +1,131 @@
using AutoMapper;
using System.Linq.Expressions;
using salesbook.Shared.Core.Dto;
using salesbook.Shared.Core.Dto.Activity;
using salesbook.Shared.Core.Dto.Contact;
using salesbook.Shared.Core.Entity;
using salesbook.Shared.Core.Helpers.Enum;
using salesbook.Shared.Core.Interface;
using Sentry.Protocol;
using System.Linq.Expressions;
namespace salesbook.Maui.Core.Services;
public class ManageDataService(LocalDbService localDb, IMapper mapper) : IManageDataService
public class ManageDataService(
LocalDbService localDb,
IMapper mapper,
IIntegryApiService integryApiService,
INetworkService networkService
) : IManageDataService
{
public Task<List<T>> GetTable<T>(Expression<Func<T, bool>>? whereCond = null) where T : new() =>
localDb.Get(whereCond);
public async Task<List<ContactDTO>> GetContact()
public async Task<List<AnagClie>> GetClienti(WhereCondContact? whereCond)
{
var contactList = await localDb.Get<AnagClie>(x => x.FlagStato.Equals("A"));
var prospectList = await localDb.Get<PtbPros>();
List<AnagClie> clienti = [];
whereCond ??= new WhereCondContact();
whereCond.OnlyContact = true;
if (networkService.ConnectionAvailable)
{
var response = await integryApiService.RetrieveAnagClie(
new CRMAnagRequestDTO
{
CodAnag = whereCond.CodAnag,
FlagStato = whereCond.FlagStato,
PartIva = whereCond.PartIva,
ReturnPersRif = !whereCond.OnlyContact
}
);
clienti = response.AnagClie ?? [];
}
else
{
clienti = await localDb.Get<AnagClie>(x =>
(whereCond.FlagStato != null && x.FlagStato.Equals(whereCond.FlagStato)) ||
(whereCond.PartIva != null && x.PartIva.Equals(whereCond.PartIva)) ||
(whereCond.PartIva == null && whereCond.FlagStato == null)
);
}
return clienti;
}
public async Task<List<PtbPros>> GetProspect(WhereCondContact? whereCond)
{
List<PtbPros> prospect = [];
whereCond ??= new WhereCondContact();
whereCond.OnlyContact = true;
if (networkService.ConnectionAvailable)
{
var response = await integryApiService.RetrieveProspect(
new CRMProspectRequestDTO
{
CodPpro = whereCond.CodAnag,
PartIva = whereCond.PartIva,
ReturnPersRif = !whereCond.OnlyContact
}
);
prospect = response.PtbPros ?? [];
}
else
{
prospect = await localDb.Get<PtbPros>(x =>
(whereCond.PartIva != null && x.PartIva.Equals(whereCond.PartIva)) ||
(whereCond.PartIva == null)
);
}
return prospect;
}
public async Task<List<ContactDTO>> GetContact(WhereCondContact? whereCond)
{
List<AnagClie>? contactList;
List<PtbPros>? prospectList;
whereCond ??= new WhereCondContact();
if (networkService.ConnectionAvailable)
{
var clienti = await integryApiService.RetrieveAnagClie(
new CRMAnagRequestDTO
{
CodAnag = whereCond.CodAnag,
FlagStato = whereCond.FlagStato,
PartIva = whereCond.PartIva,
ReturnPersRif = !whereCond.OnlyContact
}
);
_ = UpdateDbUsers(clienti);
var prospect = await integryApiService.RetrieveProspect(
new CRMProspectRequestDTO
{
CodPpro = whereCond.CodAnag,
PartIva = whereCond.PartIva,
ReturnPersRif = !whereCond.OnlyContact
}
);
_ = UpdateDbUsers(prospect);
contactList = clienti.AnagClie;
prospectList = prospect.PtbPros;
}
else
{
contactList = await localDb.Get<AnagClie>(x =>
(whereCond.FlagStato != null && x.FlagStato.Equals(whereCond.FlagStato)) ||
(whereCond.PartIva != null && x.PartIva.Equals(whereCond.PartIva)) ||
(whereCond.PartIva == null && whereCond.FlagStato == null)
);
prospectList = await localDb.Get<PtbPros>(x =>
(whereCond.PartIva != null && x.PartIva.Equals(whereCond.PartIva)) ||
(whereCond.PartIva == null)
);
}
// Mappa i contatti
var contactMapper = mapper.Map<List<ContactDTO>>(contactList);
@@ -46,9 +156,35 @@ public class ManageDataService(LocalDbService localDb, IMapper mapper) : IManage
}
}
public async Task<List<ActivityDTO>> GetActivity(Expression<Func<StbActivity, bool>>? whereCond = null)
public async Task<List<ActivityDTO>> GetActivity(WhereCondActivity whereCond, bool useLocalDb)
{
var activities = await localDb.Get(whereCond);
List<StbActivity>? activities;
if (networkService.ConnectionAvailable && !useLocalDb)
{
activities = await integryApiService.RetrieveActivity(
new CRMRetrieveActivityRequestDTO
{
StarDate = whereCond.Start,
EndDate = whereCond.End,
ActivityId = whereCond.ActivityId
}
);
_ = UpdateDb(activities);
}
else
{
activities = await localDb.Get<StbActivity>(x =>
(whereCond.ActivityId != null && x.ActivityId != null && whereCond.ActivityId.Equals(x.ActivityId)) ||
(whereCond.Start != null && whereCond.End != null && x.EffectiveDate == null &&
x.EstimatedDate >= whereCond.Start && x.EstimatedDate <= whereCond.End) ||
(x.EffectiveDate >= whereCond.Start && x.EffectiveDate <= whereCond.End) ||
(whereCond.ActivityId == null && (whereCond.Start == null || whereCond.End == null))
);
}
if (activities == null) return [];
var codJcomList = activities
.Select(x => x.CodJcom)
@@ -103,7 +239,37 @@ public class ManageDataService(LocalDbService localDb, IMapper mapper) : IManage
return returnDto;
}
public Task InsertOrUpdate<T>(List<T> listToSave) =>
private Task UpdateDbUsers(UsersSyncResponseDTO response)
{
return Task.Run(async () =>
{
if (response.AnagClie != null)
{
await localDb.InsertOrUpdate(response.AnagClie);
if (response.VtbDest != null) await localDb.InsertOrUpdate(response.VtbDest);
if (response.VtbCliePersRif != null) await localDb.InsertOrUpdate(response.VtbCliePersRif);
}
if (response.PtbPros != null)
{
await localDb.InsertOrUpdate(response.PtbPros);
if (response.PtbProsRif != null) await localDb.InsertOrUpdate(response.PtbProsRif);
}
});
}
private Task UpdateDb<T>(List<T>? entityList)
{
return Task.Run(() =>
{
if (entityList == null) return;
_ = localDb.InsertOrUpdate(entityList);
});
}
public Task InsertOrUpdate<T>(List<T> listToSave) =>
localDb.InsertOrUpdate(listToSave);
public Task InsertOrUpdate<T>(T objectToSave) =>

View File

@@ -5,17 +5,6 @@ namespace salesbook.Maui.Core.Services;
public class SyncDbService(IIntegryApiService integryApiService, LocalDbService localDb) : ISyncDbService
{
public async Task GetAndSaveActivity(string? dateFilter)
{
var allActivity = await integryApiService.RetrieveActivity(dateFilter);
if (!allActivity.IsNullOrEmpty())
if (dateFilter is null)
await localDb.InsertAll(allActivity!);
else
await localDb.InsertOrUpdate(allActivity!);
}
public async Task GetAndSaveCommesse(string? dateFilter)
{
var allCommesse = await integryApiService.RetrieveAllCommesse(dateFilter);
@@ -27,46 +16,6 @@ public class SyncDbService(IIntegryApiService integryApiService, LocalDbService
await localDb.InsertOrUpdate(allCommesse!);
}
public async Task GetAndSaveProspect(string? dateFilter)
{
var taskSyncResponseDto = await integryApiService.RetrieveProspect(dateFilter);
if (!taskSyncResponseDto.PtbPros.IsNullOrEmpty())
if (dateFilter is null)
await localDb.InsertAll(taskSyncResponseDto.PtbPros!);
else
await localDb.InsertOrUpdate(taskSyncResponseDto.PtbPros!);
if (!taskSyncResponseDto.PtbProsRif.IsNullOrEmpty())
if (dateFilter is null)
await localDb.InsertAll(taskSyncResponseDto.PtbProsRif!);
else
await localDb.InsertOrUpdate(taskSyncResponseDto.PtbProsRif!);
}
public async Task GetAndSaveClienti(string? dateFilter)
{
var taskSyncResponseDto = await integryApiService.RetrieveAnagClie(dateFilter);
if (!taskSyncResponseDto.AnagClie.IsNullOrEmpty())
if (dateFilter is null)
await localDb.InsertAll(taskSyncResponseDto.AnagClie!);
else
await localDb.InsertOrUpdate(taskSyncResponseDto.AnagClie!);
if (!taskSyncResponseDto.VtbDest.IsNullOrEmpty())
if (dateFilter is null)
await localDb.InsertAll(taskSyncResponseDto.VtbDest!);
else
await localDb.InsertOrUpdate(taskSyncResponseDto.VtbDest!);
if (!taskSyncResponseDto.VtbCliePersRif.IsNullOrEmpty())
if (dateFilter is null)
await localDb.InsertAll(taskSyncResponseDto.VtbCliePersRif!);
else
await localDb.InsertOrUpdate(taskSyncResponseDto.VtbCliePersRif!);
}
public async Task GetAndSaveSettings(string? dateFilter)
{
if (dateFilter is not null)
@@ -80,6 +29,9 @@ public class SyncDbService(IIntegryApiService integryApiService, LocalDbService
if (!settingsResponse.ActivityTypes.IsNullOrEmpty())
await localDb.InsertAll(settingsResponse.ActivityTypes!);
if (!settingsResponse.ActivityTypeUsers.IsNullOrEmpty())
await localDb.InsertAll(settingsResponse.ActivityTypeUsers!);
if (!settingsResponse.StbUsers.IsNullOrEmpty())
await localDb.InsertAll(settingsResponse.StbUsers!);

View File

@@ -4,8 +4,11 @@ namespace salesbook.Maui.Core.System.Network;
public class NetworkService : INetworkService
{
public bool ConnectionAvailable { get; set; }
public bool IsNetworkAvailable()
{
//return false;
return Connectivity.Current.NetworkAccess == NetworkAccess.Internet;
}

View File

@@ -13,6 +13,7 @@ using salesbook.Maui.Core.System.Notification;
using salesbook.Maui.Core.System.Notification.Push;
using salesbook.Shared;
using salesbook.Shared.Core.Dto;
using salesbook.Shared.Core.Dto.PageState;
using salesbook.Shared.Core.Helpers;
using salesbook.Shared.Core.Interface;
using salesbook.Shared.Core.Messages.Activity.Copy;
@@ -58,10 +59,16 @@ namespace salesbook.Maui
builder.Services.AddScoped<AuthenticationStateProvider>(provider =>
provider.GetRequiredService<AppAuthenticationStateProvider>());
builder.Services.AddScoped<INetworkService, NetworkService>();
builder.Services.AddScoped<IIntegryApiService, IntegryApiService>();
builder.Services.AddScoped<ISyncDbService, SyncDbService>();
builder.Services.AddScoped<IManageDataService, ManageDataService>();
builder.Services.AddScoped<PreloadService>();
//SessionData
builder.Services.AddSingleton<JobSteps>();
builder.Services.AddSingleton<UserPageState>();
builder.Services.AddSingleton<UserListState>();
builder.Services.AddSingleton<FilterUserDTO>();
//Message
builder.Services.AddScoped<IMessenger, WeakReferenceMessenger>();
@@ -83,8 +90,8 @@ namespace salesbook.Maui
builder.Services.AddSingleton<IFormFactor, FormFactor>();
builder.Services.AddSingleton<IAttachedService, AttachedService>();
builder.Services.AddSingleton<INetworkService, NetworkService>();
builder.Services.AddSingleton<LocalDbService>();
builder.Services.AddSingleton<FilterUserDTO>();
return builder.Build();
}