generated from Integry/Template_NetMauiBlazorHybrid
Migliorato caricamento clienti
This commit is contained in:
parent
a91e08f162
commit
e4b252f301
@ -90,14 +90,22 @@ public class ManageDataService(
|
||||
|
||||
public async Task<List<ContactDTO>> GetContact(WhereCondContact? whereCond, DateTime? lastSync)
|
||||
{
|
||||
List<AnagClie>? contactList;
|
||||
List<PtbPros>? prospectList;
|
||||
whereCond ??= new WhereCondContact();
|
||||
|
||||
// Ottengo liste locali
|
||||
var contactList = await localDb.Get<AnagClie>(x =>
|
||||
(whereCond.FlagStato != null && x.FlagStato == whereCond.FlagStato) ||
|
||||
(whereCond.PartIva != null && x.PartIva == whereCond.PartIva) ||
|
||||
(whereCond.PartIva == null && whereCond.FlagStato == null)
|
||||
);
|
||||
|
||||
var prospectList = await localDb.Get<PtbPros>(x =>
|
||||
(whereCond.PartIva != null && x.PartIva == whereCond.PartIva) ||
|
||||
(whereCond.PartIva == null)
|
||||
);
|
||||
|
||||
if (networkService.ConnectionAvailable)
|
||||
{
|
||||
var response = new UsersSyncResponseDTO();
|
||||
|
||||
var clienti = await integryApiService.RetrieveAnagClie(
|
||||
new CRMAnagRequestDTO
|
||||
{
|
||||
@ -109,10 +117,6 @@ public class ManageDataService(
|
||||
}
|
||||
);
|
||||
|
||||
response.AnagClie = clienti.AnagClie;
|
||||
response.VtbDest = clienti.VtbDest;
|
||||
response.VtbCliePersRif = clienti.VtbCliePersRif;
|
||||
|
||||
var prospect = await integryApiService.RetrieveProspect(
|
||||
new CRMProspectRequestDTO
|
||||
{
|
||||
@ -122,38 +126,62 @@ public class ManageDataService(
|
||||
FilterDate = lastSync
|
||||
}
|
||||
);
|
||||
|
||||
_ = UpdateDbUsers(new UsersSyncResponseDTO
|
||||
{
|
||||
AnagClie = clienti.AnagClie,
|
||||
VtbDest = clienti.VtbDest,
|
||||
VtbCliePersRif = clienti.VtbCliePersRif,
|
||||
PtbPros = prospect.PtbPros,
|
||||
PtbProsRif = prospect.PtbProsRif
|
||||
});
|
||||
|
||||
response.PtbPros = prospect.PtbPros;
|
||||
response.PtbProsRif = prospect.PtbProsRif;
|
||||
if (lastSync != null)
|
||||
{
|
||||
contactList = MergeLists(
|
||||
contactList,
|
||||
clienti.AnagClie,
|
||||
x => x.CodAnag
|
||||
);
|
||||
|
||||
_ = UpdateDbUsers(response);
|
||||
|
||||
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)
|
||||
);
|
||||
prospectList = MergeLists(
|
||||
prospectList,
|
||||
prospect.PtbPros,
|
||||
x => x.CodPpro
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
contactList = clienti.AnagClie;
|
||||
prospectList = prospect.PtbPros;
|
||||
}
|
||||
}
|
||||
|
||||
// Mappa i contatti
|
||||
var contactMapper = mapper.Map<List<ContactDTO>>(contactList);
|
||||
|
||||
// Mappa i prospects
|
||||
// Mappa i prospect
|
||||
var prospectMapper = mapper.Map<List<ContactDTO>>(prospectList);
|
||||
|
||||
contactMapper.AddRange(prospectMapper);
|
||||
|
||||
return contactMapper;
|
||||
}
|
||||
|
||||
private static List<T>? MergeLists<T, TKey>(List<T>? localList, List<T>? apiList, Func<T, TKey> keySelector)
|
||||
{
|
||||
if (localList == null || apiList == null) return null;
|
||||
|
||||
var dictionary = localList.ToDictionary(keySelector);
|
||||
|
||||
foreach (var apiItem in apiList)
|
||||
{
|
||||
var key = keySelector(apiItem);
|
||||
dictionary[key] = apiItem;
|
||||
}
|
||||
|
||||
return dictionary.Values.ToList();
|
||||
}
|
||||
|
||||
public async Task<ContactDTO?> GetSpecificContact(string codAnag, bool isContact)
|
||||
{
|
||||
@ -240,7 +268,7 @@ public class ManageDataService(
|
||||
.Distinct().ToList();
|
||||
|
||||
IDictionary<string, string?>? distinctUser = null;
|
||||
|
||||
|
||||
if (userListState.AllUsers != null)
|
||||
{
|
||||
distinctUser = userListState.AllUsers
|
||||
@ -251,7 +279,8 @@ public class ManageDataService(
|
||||
var returnDto = activities
|
||||
.Select(activity =>
|
||||
{
|
||||
if (activity.CodJcom is "0000" && userSession.ProfileDb != null && userSession.ProfileDb.Equals("smetar", StringComparison.OrdinalIgnoreCase))
|
||||
if (activity.CodJcom is "0000" && userSession.ProfileDb != null &&
|
||||
userSession.ProfileDb.Equals("smetar", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
activity.CodJcom = null;
|
||||
}
|
||||
@ -263,8 +292,7 @@ public class ManageDataService(
|
||||
var minuteBefore = activity.EstimatedTime.Value - activity.AlarmTime.Value;
|
||||
dto.MinuteBefore = (int)Math.Abs(minuteBefore.TotalMinutes);
|
||||
|
||||
dto.NotificationDate = dto.MinuteBefore == 0 ?
|
||||
activity.EstimatedTime : activity.AlarmTime;
|
||||
dto.NotificationDate = dto.MinuteBefore == 0 ? activity.EstimatedTime : activity.AlarmTime;
|
||||
}
|
||||
|
||||
if (activity.CodJcom != null)
|
||||
@ -281,7 +309,7 @@ public class ManageDataService(
|
||||
string? ragSoc;
|
||||
|
||||
if (distinctUser != null && (distinctUser.TryGetValue(activity.CodAnag, out ragSoc) ||
|
||||
distinctUser.TryGetValue(activity.CodAnag, out ragSoc)))
|
||||
distinctUser.TryGetValue(activity.CodAnag, out ragSoc)))
|
||||
{
|
||||
dto.Cliente = ragSoc;
|
||||
}
|
||||
@ -343,7 +371,7 @@ public class ManageDataService(
|
||||
public async Task DeleteProspect(string codPpro)
|
||||
{
|
||||
var persRifList = await GetTable<PtbProsRif>(x => x.CodPpro!.Equals(codPpro));
|
||||
|
||||
|
||||
if (!persRifList.IsNullOrEmpty())
|
||||
{
|
||||
foreach (var persRif in persRifList)
|
||||
|
||||
@ -88,7 +88,7 @@
|
||||
FullWidth="true"
|
||||
StartIcon="@Icons.Material.Outlined.Sync"
|
||||
Size="Size.Medium"
|
||||
OnClick="() => UpdateDb()"
|
||||
OnClick="@(() => UpdateDb())"
|
||||
Variant="Variant.Outlined">
|
||||
Sincronizza
|
||||
</MudButton>
|
||||
@ -154,6 +154,8 @@
|
||||
|
||||
private void UpdateDb(bool withData = false)
|
||||
{
|
||||
LocalStorage.Remove("last-user-sync");
|
||||
|
||||
var absoluteUri = NavigationManager.ToAbsoluteUri(NavigationManager.Uri);
|
||||
var pathAndQuery = absoluteUri.Segments.Length > 1 ? absoluteUri.PathAndQuery : null;
|
||||
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
using salesbook.Shared.Core.Dto;
|
||||
using IntegryApiClient.Core.Domain.Abstraction.Contracts.Storage;
|
||||
using Java.Sql;
|
||||
using salesbook.Shared.Core.Dto;
|
||||
using salesbook.Shared.Core.Dto.Contact;
|
||||
using salesbook.Shared.Core.Dto.PageState;
|
||||
using salesbook.Shared.Core.Dto.Users;
|
||||
@ -6,7 +8,7 @@ using salesbook.Shared.Core.Interface;
|
||||
|
||||
namespace salesbook.Shared.Core.Services;
|
||||
|
||||
public class PreloadService(IManageDataService manageData, UserListState userState)
|
||||
public class PreloadService(IManageDataService manageData, ILocalStorage localStorage, UserListState userState)
|
||||
{
|
||||
public async Task PreloadUsersAsync()
|
||||
{
|
||||
@ -14,8 +16,11 @@ public class PreloadService(IManageDataService manageData, UserListState userSta
|
||||
return;
|
||||
|
||||
userState.IsLoading = true;
|
||||
|
||||
DateTime? lastSync = localStorage.Get<DateTime>("last-user-sync");
|
||||
lastSync = lastSync.Equals(DateTime.MinValue) ? null : lastSync;
|
||||
|
||||
var users = await manageData.GetContact(new WhereCondContact { FlagStato = "A" });
|
||||
var users = await manageData.GetContact(new WhereCondContact { FlagStato = "A" }, lastSync);
|
||||
|
||||
var sorted = users
|
||||
.Where(u => !string.IsNullOrWhiteSpace(u.RagSoc))
|
||||
@ -27,6 +32,8 @@ public class PreloadService(IManageDataService manageData, UserListState userSta
|
||||
userState.FilteredGroupedUserList = userState.GroupedUserList;
|
||||
userState.AllUsers = users;
|
||||
|
||||
localStorage.Set("last-user-sync", DateTime.Now);
|
||||
|
||||
userState.NotifyUsersLoaded();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user