diff --git a/salesbook.Maui/Core/Services/ManageDataService.cs b/salesbook.Maui/Core/Services/ManageDataService.cs index 44c5c83..77d8978 100644 --- a/salesbook.Maui/Core/Services/ManageDataService.cs +++ b/salesbook.Maui/Core/Services/ManageDataService.cs @@ -126,15 +126,29 @@ public class ManageDataService( FilterDate = lastSync } ); - - _ = UpdateDbUsers(new UsersSyncResponseDTO + + if (lastSync == null) { - AnagClie = clienti.AnagClie, - VtbDest = clienti.VtbDest, - VtbCliePersRif = clienti.VtbCliePersRif, - PtbPros = prospect.PtbPros, - PtbProsRif = prospect.PtbProsRif - }); + await InsertDbUsers(new UsersSyncResponseDTO + { + AnagClie = clienti.AnagClie, + VtbDest = clienti.VtbDest, + VtbCliePersRif = clienti.VtbCliePersRif, + PtbPros = prospect.PtbPros, + PtbProsRif = prospect.PtbProsRif + }); + } + else + { + _ = UpdateDbUsers(new UsersSyncResponseDTO + { + AnagClie = clienti.AnagClie, + VtbDest = clienti.VtbDest, + VtbCliePersRif = clienti.VtbCliePersRif, + PtbPros = prospect.PtbPros, + PtbProsRif = prospect.PtbProsRif + }); + } if (lastSync != null) { @@ -325,6 +339,24 @@ public class ManageDataService( return returnDto; } + private async Task InsertDbUsers(UsersSyncResponseDTO response) + { + if (response.AnagClie != null) + { + await localDb.InsertAll(response.AnagClie); + + if (response.VtbDest != null) await localDb.InsertAll(response.VtbDest); + if (response.VtbCliePersRif != null) await localDb.InsertAll(response.VtbCliePersRif); + } + + if (response.PtbPros != null) + { + await localDb.InsertAll(response.PtbPros); + + if (response.PtbProsRif != null) await localDb.InsertAll(response.PtbProsRif); + } + } + private Task UpdateDbUsers(UsersSyncResponseDTO response) { return Task.Run(async () => diff --git a/salesbook.Shared/Components/Pages/PersonalInfo.razor b/salesbook.Shared/Components/Pages/PersonalInfo.razor index e0810c7..a636dec 100644 --- a/salesbook.Shared/Components/Pages/PersonalInfo.razor +++ b/salesbook.Shared/Components/Pages/PersonalInfo.razor @@ -3,12 +3,14 @@ @using salesbook.Shared.Components.Layout @using salesbook.Shared.Components.SingleElements @using salesbook.Shared.Core.Authorization.Enum +@using salesbook.Shared.Core.Dto.PageState @using salesbook.Shared.Core.Interface @using salesbook.Shared.Core.Interface.System.Network @using salesbook.Shared.Core.Services @inject AppAuthenticationStateProvider AuthenticationStateProvider @inject INetworkService NetworkService @inject IFormFactor FormFactor +@inject UserListState UserState @@ -155,18 +157,10 @@ 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; + UserState.IsLoaded = false; + UserState.IsLoading = false; - string path; - - if (withData) - path = pathAndQuery == null ? $"/sync/{DateTime.Today:yyyy-MM-dd}" : $"/sync/{DateTime.Today:yyyy-MM-dd}?path=" + System.Web.HttpUtility.UrlEncode(pathAndQuery); - else - path = pathAndQuery == null ? "/sync" : "/sync?path=" + System.Web.HttpUtility.UrlEncode(pathAndQuery); - - NavigationManager.NavigateTo(path, replace: true); + NavigationManager.NavigateTo(withData ? $"/sync/{DateTime.Today:yyyy-MM-dd}" : "/sync", replace: true); } } \ No newline at end of file diff --git a/salesbook.Shared/Components/Pages/SyncPage.razor b/salesbook.Shared/Components/Pages/SyncPage.razor index 7c93c2a..163310c 100644 --- a/salesbook.Shared/Components/Pages/SyncPage.razor +++ b/salesbook.Shared/Components/Pages/SyncPage.razor @@ -3,8 +3,10 @@ @using salesbook.Shared.Components.Layout.Spinner @using salesbook.Shared.Components.SingleElements @using salesbook.Shared.Core.Interface +@using salesbook.Shared.Core.Services @inject ISyncDbService SyncDb @inject IManageDataService ManageData +@inject PreloadService PreloadService @@ -55,6 +57,11 @@ var originalPath = pathQuery["path"] ?? null; var path = originalPath ?? "/Calendar"; + if (path.Equals("/Calendar") && DateFilter is null) + { + _ = Task.Run(() => { _ = PreloadService.PreloadUsersAsync(); }); + } + NavigationManager.NavigateTo(path, replace: true); } } diff --git a/salesbook.Shared/Components/Pages/User.razor b/salesbook.Shared/Components/Pages/User.razor index e42f70b..9cb1386 100644 --- a/salesbook.Shared/Components/Pages/User.razor +++ b/salesbook.Shared/Components/Pages/User.razor @@ -23,7 +23,7 @@ OnSave="() => OpenUserForm(Anag)" Back="true" BackOnTop="true" - Title="" + Title="@Anag.CodContact" ShowProfile="false"/> @if (IsLoading) @@ -111,7 +111,7 @@ else
  • - +
  • @@ -219,7 +219,7 @@ else } - +
    @if (ActivityIsLoading) { @@ -227,7 +227,7 @@ else } else if (ActivityList?.Count == 0) { - + } else if (ActivityList != null) { @@ -309,7 +309,7 @@ else private string _searchTermCommesse = string.Empty; private List _filteredCommesse = []; - // Paginazione e filtri per ATTIVITÀ + // Paginazione e filtri per attività private int _currentPageActivity = 1; private int _selectedPageSizeActivity = 5; private string _searchTermActivity = string.Empty; @@ -381,7 +381,7 @@ else #endregion - #region Properties per Attività + #region Properties per Attività private int CurrentPageActivityIndex { @@ -445,7 +445,7 @@ else { _loadingCts = new CancellationTokenSource(); - if (UserState.CodUser?.Equals(CodContact) == true) + if (UserState.CodUser != null && UserState.CodUser.Equals(CodContact)) { LoadDataFromSession(); }