340 lines
8.4 KiB
C#
340 lines
8.4 KiB
C#
using Blazored.LocalStorage;
|
|
using Blazored.SessionStorage;
|
|
using GPW.CORE.Data.DbModels;
|
|
using GPW.CORE.Data.DTO;
|
|
using StackExchange.Redis;
|
|
using System.Reflection.Metadata;
|
|
|
|
namespace GPW.CORE.Data.Services
|
|
{
|
|
public class MessageService
|
|
{
|
|
#region Public Fields
|
|
|
|
public int orarioDip = 0;
|
|
|
|
#endregion Public Fields
|
|
|
|
#region Public Constructors
|
|
|
|
public MessageService(ILocalStorageService genLocalStorage, ISessionStorageService sessStore)
|
|
{
|
|
// gestione sessioni in browser
|
|
localStore = genLocalStorage;
|
|
sessionStore = sessStore;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Events
|
|
|
|
public event Action EA_HideSearch = null!;
|
|
|
|
public event Action EA_LangSel = null!;
|
|
|
|
public event Action EA_MenuUpdated = null!;
|
|
|
|
public event Action EA_PageUpdated = null!;
|
|
|
|
public event Action EA_SearchUpdated = null!;
|
|
|
|
public event Action EA_ShowSearch = null!;
|
|
|
|
public event Action EA_UserUpdated = null!;
|
|
|
|
#endregion Public Events
|
|
|
|
#region Public Properties
|
|
|
|
public RegAttivitaModel? clonedRA { get; set; } = null;
|
|
|
|
/// <summary>
|
|
/// Calcola HASH del codice impiego = payload utente
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string HashDip
|
|
{
|
|
get
|
|
{
|
|
DataValidator cDV = new DataValidator(_rigaDip);
|
|
string hash = cDV.HashDip;
|
|
return hash;
|
|
}
|
|
}
|
|
|
|
public int IdxDipendente
|
|
{
|
|
get
|
|
{
|
|
int answ = -1;
|
|
if (_rigaDip != null)
|
|
{
|
|
answ = _rigaDip.IdxDipendente;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
public bool IsActive
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
if (_rigaDip != null && _rigaDip.Attivo != null)
|
|
{
|
|
answ = (bool)_rigaDip.Attivo;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
public List<MenuItemDTO> ListMenu
|
|
{
|
|
get => _listMenu;
|
|
set
|
|
{
|
|
_listMenu = value;
|
|
if (EA_MenuUpdated != null)
|
|
{
|
|
EA_MenuUpdated?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
|
|
public string PageIcon
|
|
{
|
|
get => _pageIcon;
|
|
set
|
|
{
|
|
if (_pageIcon != value)
|
|
{
|
|
_pageIcon = value;
|
|
ReportPageUpd();
|
|
}
|
|
}
|
|
}
|
|
|
|
public string PageName
|
|
{
|
|
get => _pageName;
|
|
set
|
|
{
|
|
if (_pageName != value)
|
|
{
|
|
_pageName = value;
|
|
ReportPageUpd();
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool PayloadOk { get; set; } = false;
|
|
|
|
public RegAttivitaModel? recordRA { get; set; } = null;
|
|
|
|
public DipendentiModel? RigaDip
|
|
{
|
|
get => _rigaDip;
|
|
set
|
|
{
|
|
if (_rigaDip != value)
|
|
{
|
|
_rigaDip = value;
|
|
|
|
if (EA_UserUpdated != null)
|
|
{
|
|
EA_UserUpdated?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public string SearchVal
|
|
{
|
|
get => _searchVal;
|
|
set
|
|
{
|
|
if (_searchVal != value)
|
|
{
|
|
_searchVal = value;
|
|
|
|
if (EA_SearchUpdated != null)
|
|
{
|
|
EA_SearchUpdated?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public int selWeekNum { get; set; } = 0;
|
|
|
|
public int selYear { get; set; } = DateTime.Today.Year;
|
|
|
|
public bool ShowSearch
|
|
{
|
|
get => showSearch;
|
|
set
|
|
{
|
|
if (showSearch != value)
|
|
{
|
|
showSearch = value;
|
|
if (showSearch)
|
|
{
|
|
if (EA_ShowSearch != null)
|
|
{
|
|
EA_ShowSearch?.Invoke();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (EA_HideSearch != null)
|
|
{
|
|
EA_HideSearch?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public DateTime targetDate { get; set; } = DateTime.Today;
|
|
|
|
public string UserLang
|
|
{
|
|
get => userLang;
|
|
set
|
|
{
|
|
if (userLang != value)
|
|
{
|
|
userLang = value;
|
|
if (EA_LangSel != null)
|
|
{
|
|
EA_LangSel?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public string UserName
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
if (_rigaDip != null)
|
|
{
|
|
answ = _rigaDip.Utente;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Num record x la pagina corrente
|
|
/// </summary>
|
|
public async Task<int> NumRowGridGet(string gridName)
|
|
{
|
|
var answ = await localStore.GetItemAsync<int>($"{gridName}_nRow");
|
|
answ = answ > 0 ? answ : 10;
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Imposta num record x la pagina corrente
|
|
/// </summary>
|
|
public async Task NumRowGridSet(string gridName, int newVal)
|
|
{
|
|
await localStore.SetItemAsync($"{gridName}_nRow", newVal);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lingua richiesta da utente
|
|
/// </summary>
|
|
public async Task<string> UserLangGet()
|
|
{
|
|
var answ = await localStore.GetItemAsync<string>("UserLang");
|
|
answ = string.IsNullOrEmpty(answ) ? "IT" : answ;
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva lingua utente
|
|
/// </summary>
|
|
public async Task UserLangSet(string userLangl)
|
|
{
|
|
await localStore.SetItemAsync("UserLang", userLang);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Preferenza utente salvata in local storage
|
|
/// </summary>
|
|
public async Task<string> UserPrefGet(string userPref)
|
|
{
|
|
string rawData = await localStore.GetItemAsStringAsync(userPref) ?? "";
|
|
return rawData;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Preferenza utente salvata in local storage
|
|
/// </summary>
|
|
public async ValueTask<T?> UserPrefGet<T>(string userPref)
|
|
{
|
|
var sData = await localStore.GetItemAsync<string>(userPref);
|
|
if (string.IsNullOrEmpty(sData))
|
|
{
|
|
return default(T);
|
|
}
|
|
else
|
|
{
|
|
return (T)Convert.ChangeType(sData, typeof(T));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Imposta pref utente
|
|
/// </summary>
|
|
public async Task UserPrefSet(string userPref, string newVal)
|
|
{
|
|
await localStore.SetItemAsync(userPref, newVal);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
protected List<MenuItemDTO> _listMenu { get; set; } = new List<MenuItemDTO>();
|
|
protected ILocalStorageService localStore { get; set; } = null!;
|
|
protected ISessionStorageService sessionStore { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Private Fields
|
|
|
|
private string _pageIcon = "";
|
|
private string _pageName = "";
|
|
private DipendentiModel? _rigaDip;
|
|
private string _searchVal = "";
|
|
private bool showSearch;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private string userLang { get; set; } = "IT";
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void ReportPageUpd()
|
|
{
|
|
if (EA_PageUpdated != null)
|
|
{
|
|
EA_PageUpdated?.Invoke();
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |