generated from Integry/Template_NetMauiBlazorHybrid
Compare commits
7 Commits
39c34e7c7d
...
70e68e59fb
| Author | SHA1 | Date | |
|---|---|---|---|
| 70e68e59fb | |||
| 032dd78c8c | |||
| e4b252f301 | |||
| a91e08f162 | |||
| 3fd5410bf5 | |||
| e338e7d253 | |||
| d982aa9bf5 |
@ -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)
|
||||
|
||||
8
salesbook.Maui/Core/System/GenericSystemService.cs
Normal file
8
salesbook.Maui/Core/System/GenericSystemService.cs
Normal file
@ -0,0 +1,8 @@
|
||||
using salesbook.Shared.Core.Interface.System;
|
||||
|
||||
namespace salesbook.Maui.Core.System;
|
||||
|
||||
public class GenericSystemService : IGenericSystemService
|
||||
{
|
||||
public string GetCurrentAppVersion() => AppInfo.VersionString;
|
||||
}
|
||||
@ -7,6 +7,7 @@ using MudBlazor.Services;
|
||||
using MudExtensions.Services;
|
||||
using salesbook.Maui.Core.RestClient.IntegryApi;
|
||||
using salesbook.Maui.Core.Services;
|
||||
using salesbook.Maui.Core.System;
|
||||
using salesbook.Maui.Core.System.Network;
|
||||
using salesbook.Maui.Core.System.Notification;
|
||||
using salesbook.Maui.Core.System.Notification.Push;
|
||||
@ -16,6 +17,7 @@ using salesbook.Shared.Core.Dto.PageState;
|
||||
using salesbook.Shared.Core.Helpers;
|
||||
using salesbook.Shared.Core.Interface;
|
||||
using salesbook.Shared.Core.Interface.IntegryApi;
|
||||
using salesbook.Shared.Core.Interface.System;
|
||||
using salesbook.Shared.Core.Interface.System.Network;
|
||||
using salesbook.Shared.Core.Interface.System.Notification;
|
||||
using salesbook.Shared.Core.Messages.Activity.Copy;
|
||||
@ -102,6 +104,7 @@ namespace salesbook.Maui
|
||||
builder.Services.AddSingleton<IFormFactor, FormFactor>();
|
||||
builder.Services.AddSingleton<IAttachedService, AttachedService>();
|
||||
builder.Services.AddSingleton<INetworkService, NetworkService>();
|
||||
builder.Services.AddSingleton<IGenericSystemService, GenericSystemService>();
|
||||
builder.Services.AddSingleton<LocalDbService>();
|
||||
|
||||
_ = typeof(System.Runtime.InteropServices.SafeHandle);
|
||||
|
||||
@ -29,8 +29,8 @@
|
||||
<ApplicationId>it.integry.salesbook</ApplicationId>
|
||||
|
||||
<!-- Versions -->
|
||||
<ApplicationDisplayVersion>2.1.5</ApplicationDisplayVersion>
|
||||
<ApplicationVersion>23</ApplicationVersion>
|
||||
<ApplicationDisplayVersion>2.2.0</ApplicationDisplayVersion>
|
||||
<ApplicationVersion>24</ApplicationVersion>
|
||||
|
||||
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
|
||||
<!--<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
{
|
||||
var lastSyncDate = LocalStorage.Get<DateTime>("last-sync");
|
||||
var syncAllData = lastSyncDate.Equals(DateTime.MinValue) || (DateTime.Now - lastSyncDate).TotalDays >= 7;
|
||||
var syncCodJcom = lastSyncDate.Day != DateTime.Now.Day;
|
||||
|
||||
if (!FormFactor.IsWeb() && NetworkService.ConnectionAvailable && syncAllData)
|
||||
{
|
||||
@ -31,6 +32,13 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (syncCodJcom && !syncAllData)
|
||||
{
|
||||
var returnPath = System.Web.HttpUtility.UrlEncode("/");
|
||||
NavigationManager.NavigateTo($"/sync/{DateTime.Today:yyyy-MM-dd}?path={returnPath}");
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkService.ConnectionAvailable = NetworkService.IsNetworkAvailable();
|
||||
|
||||
await LoadNotification();
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
@page "/login"
|
||||
@using salesbook.Shared.Components.Layout.Spinner
|
||||
@using salesbook.Shared.Core.Interface.System
|
||||
@using salesbook.Shared.Core.Services
|
||||
@inject IUserAccountService UserAccountService
|
||||
@inject AppAuthenticationStateProvider AuthenticationStateProvider
|
||||
@inject IGenericSystemService GenericSystemService
|
||||
|
||||
@if (Spinner)
|
||||
{
|
||||
@ -34,7 +36,7 @@ else
|
||||
</div>
|
||||
|
||||
<div class="my-4 login-footer">
|
||||
<span>Powered by</span>
|
||||
<span>@($"v{GenericSystemService.GetCurrentAppVersion()} | Powered by")</span>
|
||||
<img src="_content/salesbook.Shared/images/logoIntegry.svg" class="img-fluid" alt="Integry">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
@page "/PersonalInfo"
|
||||
@attribute [Authorize]
|
||||
@using salesbook.Shared.Components.Layout
|
||||
@using salesbook.Shared.Components.SingleElements
|
||||
@using salesbook.Shared.Core.Authorization.Enum
|
||||
@using salesbook.Shared.Core.Interface
|
||||
@using salesbook.Shared.Core.Interface.System.Network
|
||||
@ -16,7 +17,8 @@
|
||||
<div class="container content pb-safe-area">
|
||||
<div class="container-primary-info">
|
||||
<div class="section-primary-info">
|
||||
<MudAvatar Style="height: 70px; width: 70px; font-size: 2rem; font-weight: bold" Color="Color.Secondary">
|
||||
<MudAvatar Style="height: 70px; width: 70px; font-size: 2rem; font-weight: bold"
|
||||
Color="Color.Secondary">
|
||||
@UtilityString.ExtractInitials(UserSession.User.Fullname)
|
||||
</MudAvatar>
|
||||
|
||||
@ -24,7 +26,8 @@
|
||||
<span class="info-nome">@UserSession.User.Fullname</span>
|
||||
@if (UserSession.User.KeyGroup is not null)
|
||||
{
|
||||
<span class="info-section">@(((KeyGroupEnum)UserSession.User.KeyGroup).ConvertToHumanReadable())</span>
|
||||
<span
|
||||
class="info-section">@(((KeyGroupEnum)UserSession.User.KeyGroup).ConvertToHumanReadable())</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@ -85,7 +88,7 @@
|
||||
FullWidth="true"
|
||||
StartIcon="@Icons.Material.Outlined.Sync"
|
||||
Size="Size.Medium"
|
||||
OnClick="() => UpdateDb()"
|
||||
OnClick="@(() => UpdateDb())"
|
||||
Variant="Variant.Outlined">
|
||||
Sincronizza
|
||||
</MudButton>
|
||||
@ -113,6 +116,8 @@
|
||||
</MudButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AppVersion/>
|
||||
}
|
||||
|
||||
@code {
|
||||
@ -149,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,24 +1,29 @@
|
||||
@page "/sync"
|
||||
@page "/sync/{DateFilter}"
|
||||
@using salesbook.Shared.Components.Layout.Spinner
|
||||
@using salesbook.Shared.Components.SingleElements
|
||||
@using salesbook.Shared.Core.Interface
|
||||
@inject ISyncDbService syncDb
|
||||
@inject IManageDataService manageData
|
||||
@inject ISyncDbService SyncDb
|
||||
@inject IManageDataService ManageData
|
||||
|
||||
<SyncSpinner Elements="@Elements"/>
|
||||
|
||||
<AppVersion/>
|
||||
|
||||
@code {
|
||||
[Parameter] public string? DateFilter { get; set; }
|
||||
|
||||
private Dictionary<string, bool> Elements { get; set; } = new();
|
||||
|
||||
private bool _hasStarted = false;
|
||||
private int _completedCount = 0;
|
||||
private bool _hasStarted;
|
||||
private int _completedCount;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Elements["Commesse"] = false;
|
||||
Elements["Impostazioni"] = false;
|
||||
|
||||
if (DateFilter is null)
|
||||
Elements["Impostazioni"] = false;
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
@ -28,9 +33,7 @@
|
||||
_hasStarted = true;
|
||||
|
||||
if (DateFilter is null)
|
||||
{
|
||||
await manageData.ClearDb();
|
||||
}
|
||||
await ManageData.ClearDb();
|
||||
|
||||
await Task.WhenAll(
|
||||
RunAndTrack(SetCommesse),
|
||||
@ -58,7 +61,7 @@
|
||||
|
||||
private async Task SetCommesse()
|
||||
{
|
||||
await Task.Run(async () => { await syncDb.GetAndSaveCommesse(DateFilter); });
|
||||
await Task.Run(async () => { await SyncDb.GetAndSaveCommesse(DateFilter); });
|
||||
|
||||
Elements["Commesse"] = true;
|
||||
StateHasChanged();
|
||||
@ -66,10 +69,13 @@
|
||||
|
||||
private async Task SetSettings()
|
||||
{
|
||||
await Task.Run(async () => { await syncDb.GetAndSaveSettings(DateFilter); });
|
||||
if (DateFilter is null)
|
||||
{
|
||||
await Task.Run(async () => { await SyncDb.GetAndSaveSettings(DateFilter); });
|
||||
|
||||
Elements["Impostazioni"] = true;
|
||||
StateHasChanged();
|
||||
Elements["Impostazioni"] = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
@using salesbook.Shared.Core.Interface.System
|
||||
@inject IGenericSystemService GenericSystemService
|
||||
|
||||
<div class="app-version">
|
||||
<span>@($"v{GenericSystemService.GetCurrentAppVersion()}")</span>
|
||||
</div>
|
||||
@ -0,0 +1,11 @@
|
||||
.app-version{
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
.app-version span{
|
||||
font-size: smaller;
|
||||
color: var(--mud-palette-gray-darker);
|
||||
}
|
||||
@ -460,7 +460,10 @@
|
||||
|
||||
Users = await ManageData.GetTable<StbUser>();
|
||||
if (!ActivityModel.UserName.IsNullOrEmpty())
|
||||
{
|
||||
SelectedUser = Users.FindLast(x => x.UserName.Equals(ActivityModel.UserName));
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
if (!IsNew && Id != null)
|
||||
ActivityFileList = await IntegryApiService.GetActivityFile(Id);
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
namespace salesbook.Shared.Core.Interface.System;
|
||||
|
||||
public interface IGenericSystemService
|
||||
{
|
||||
string GetCurrentAppVersion();
|
||||
}
|
||||
@ -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