Files
mapo-core/MP.SPEC/Data/MsgServiceSpec.cs
2026-02-25 11:41:19 +01:00

163 lines
3.8 KiB
C#

using Microsoft.AspNetCore.Components;
using MP.AppAuth.Models;
namespace MP.SPEC.Data
{
public class MsgServiceSpec
{
#region Public Events
public event Action EA_BroadCastMsg = null!;
public event Action EA_PageUpdated = null!;
#endregion Public Events
#region Public Properties
/// <summary>
/// Dominio utente
/// </summary>
public string DomainName { get; set; } = "";
/// <summary>
/// Elenco link utente
/// </summary>
public List<MP.Data.DbModels.LinkMenuModel>? ElencoLink { get; set; } = null;
public string newBCMsg
{
get => _newBCMsg;
set
{
if (_newBCMsg != value)
{
_newBCMsg = value;
reportMsg();
}
}
}
public string PageIcon
{
get => _pageIcon;
set
{
if (_pageIcon != value)
{
_pageIcon = value;
ReportPageUpd();
}
}
}
public string PageName
{
get => _pageName;
set
{
if (_pageName != value)
{
_pageName = value;
ReportPageUpd();
}
}
}
/// <summary>
/// Username utente
/// </summary>
public string UserName { get; set; } = "";
/// <summary>
/// Diritti utente (solo Funzione/Ruolo)
/// </summary>
public List<string> UserRight
{
get => _userRight;
set
{
_userRight = value;
ReportPageUpd();
}
}
#endregion Public Properties
#region Public Methods
/// <summary>
/// Verifica ruolo utente
/// </summary>
/// <param name="Ruolo"></param>
/// <returns></returns>
public bool HasRole(string Ruolo)
{
bool answ = false;
if (UserRight != null && UserRight.Count > 0)
{
answ = UserRight
.Where(x => x.Equals(Ruolo, StringComparison.InvariantCultureIgnoreCase))
.Count() > 0;
}
return answ;
}
/// <summary>
/// Segnala cambio pagina
/// </summary>
/// <returns></returns>
public void ReportPageUpd()
{
if (EA_PageUpdated != null)
{
EA_PageUpdated?.Invoke();
}
}
/// <summary>
/// Imposta i dati della pagina corrente dato l'url
/// </summary>
/// <param name="pageUrl"></param>
public void SetPage(string pageUrl)
{
if (ElencoLink != null)
{
var recLink = ElencoLink.FirstOrDefault(x => x.NavigateUrl == pageUrl);
if (recLink != null)
{
_pageIcon = recLink.Icona;
PageName = recLink.Testo;
}
}
}
#endregion Public Methods
#region Protected Methods
protected void reportMsg()
{
if (EA_BroadCastMsg != null)
{
EA_BroadCastMsg?.Invoke();
}
}
#endregion Protected Methods
#region Private Fields
private string _pageIcon = "";
private string _pageName = "";
#endregion Private Fields
#region Private Properties
private string _newBCMsg { get; set; } = "";
private List<string> _userRight { get; set; } = new List<string>();
#endregion Private Properties
}
}