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 /// /// Dominio utente /// public string DomainName { get; set; } = ""; /// /// Elenco link utente /// public List? 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(); } } } /// /// Username utente /// public string UserName { get; set; } = ""; /// /// Diritti utente (solo Funzione/Ruolo) /// public List UserRight { get => _userRight; set { _userRight = value; ReportPageUpd(); } } #endregion Public Properties #region Public Methods /// /// Verifica ruolo utente /// /// /// 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; } /// /// Segnala cambio pagina /// /// public void ReportPageUpd() { if (EA_PageUpdated != null) { EA_PageUpdated?.Invoke(); } } /// /// Imposta i dati della pagina corrente dato l'url /// /// 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 _userRight { get; set; } = new List(); #endregion Private Properties } }