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