From bbec081caef4b038d4b3e8fee8508d5469d7301c Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 4 Nov 2022 09:29:43 +0100 Subject: [PATCH] Separato codice cs x CmpTop --- MP.SPEC/Components/CmpTop.razor | 59 --------------------- MP.SPEC/Components/CmpTop.razor.cs | 84 ++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 59 deletions(-) create mode 100644 MP.SPEC/Components/CmpTop.razor.cs diff --git a/MP.SPEC/Components/CmpTop.razor b/MP.SPEC/Components/CmpTop.razor index 4e8840bd..b48edbec 100644 --- a/MP.SPEC/Components/CmpTop.razor +++ b/MP.SPEC/Components/CmpTop.razor @@ -24,63 +24,4 @@ *@ -@code { - protected bool ShowSearch - { - get => MService.ShowSearch; - set => MService.ShowSearch = value; - } - private string userName = ""; - - private string TipoSearch - { - get => MService.TipoSearch; - set => MService.TipoSearch = value; - } - - protected override async Task OnInitializedAsync() - { - MService.EA_ShowSearch += MService_EA_ShowSearch; - await forceReload(); - } - private async void MService_EA_ShowSearch() - { - await Task.Delay(1); - await InvokeAsync(() => StateHasChanged()); - } - - private async Task forceReload() - { - - var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); - var user = authState.User; - - if (user.Identity != null&& user.Identity.IsAuthenticated) - { - userName = $"{user.Identity.Name}"; - } - else - { - userName = "N.A."; - } - } - - public async Task flushCache() - { - await Task.Delay(1); - await MDService.FlushRedisCache(); - await Task.Delay(1); - // rimando a pagina corrente - NavManager.NavigateTo(NavManager.Uri, true); - } - - [Inject] - private NavigationManager NavManager { get; set; } = null!; - - [Inject] - protected MpDataService MDService { get; set; } = null!; - - [Inject] - protected IJSRuntime JSRuntime { get; set; } = null!; -} diff --git a/MP.SPEC/Components/CmpTop.razor.cs b/MP.SPEC/Components/CmpTop.razor.cs new file mode 100644 index 00000000..7668ad34 --- /dev/null +++ b/MP.SPEC/Components/CmpTop.razor.cs @@ -0,0 +1,84 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.JSInterop; +using MP.SPEC.Data; + +namespace MP.SPEC.Components +{ + public partial class CmpTop + { + #region Public Methods + + public async Task flushCache() + { + await Task.Delay(1); + await MDService.FlushRedisCache(); + await Task.Delay(1); + // rimando a pagina corrente + NavManager.NavigateTo(NavManager.Uri, true); + } + + #endregion Public Methods + + #region Protected Properties + + [Inject] + protected IJSRuntime JSRuntime { get; set; } = null!; + + [Inject] + protected MpDataService MDService { get; set; } = null!; + + protected bool ShowSearch { get => MService.ShowSearch; set => MService.ShowSearch = value; } + + #endregion Protected Properties + + #region Protected Methods + + protected override async Task OnInitializedAsync() + { + MService.EA_ShowSearch += MService_EA_ShowSearch; + await forceReload(); + } + + #endregion Protected Methods + + #region Private Fields + + private string userName = ""; + + #endregion Private Fields + + #region Private Properties + + [Inject] + private NavigationManager NavManager { get; set; } = null!; + + private string TipoSearch { get => MService.TipoSearch; set => MService.TipoSearch = value; } + + #endregion Private Properties + + #region Private Methods + + private async Task forceReload() + { + var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + var user = authState.User; + if (user.Identity != null && user.Identity.IsAuthenticated) + { + userName = $"{user.Identity.Name}"; + } + else + { + userName = "N.A."; + } + } + + private async void MService_EA_ShowSearch() + { + await Task.Delay(1); + await InvokeAsync(() => StateHasChanged()); + } + + #endregion Private Methods + } +} \ No newline at end of file