Files
mapo-core/MP.INVE/Pages/Starter.razor.cs
T
2022-11-16 15:49:37 +01:00

85 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using System.Net.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.Virtualization;
using Microsoft.JSInterop;
using MP.INVE;
using MP.INVE.Shared;
using MP.INVE.Components;
using Blazored.SessionStorage;
using MP.Data.DTO;
using MP.INVE.Data;
using Blazored.LocalStorage;
namespace MP.INVE.Pages
{
public partial class Starter
{
[Inject]
private IConfiguration Configuration { get; set; } = null!;
[Inject]
private ISessionStorageService sessionStorage { get; set; } = null!;
[Inject]
private ILocalStorageService localStorage { get; set; } = null!;
[Inject]
private MiDataService MIDataservice { get; set; } = null!;
private int idOperatore { get; set; } = 0;
private string authKey { get; set; } = "";
protected override async Task OnInitializedAsync()
{
await getId();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JSRuntime.InvokeVoidAsync("clearContent", $"qrCodeImg_{101}");
await JSRuntime.InvokeVoidAsync("displayQr", $"qrCodeImg_{101}", rawCode);
}
}
protected string BaseUrlTab { get => $"{Configuration["ServerConf:BaseUrl"]}"; }
protected async Task getId()
{
OperatoreDTO sess = new OperatoreDTO();
OperatoreDTO local = new OperatoreDTO();
sess = await sessionStorage.GetItemAsync<OperatoreDTO>("MatrOpr");
local = await localStorage.GetItemAsync<OperatoreDTO>("MatrOpr");
if ((local != null))
{
string auth = local.hashAuthKey;
idOperatore = local.MatrOpr;
authKey = auth;
}
else
{
NavManager.NavigateTo("OperatoreLogin");
}
}
[Inject]
private NavigationManager NavManager { get; set; } = null!;
protected string rawCode
{
get
{
string answ = "";
answ = $"{BaseUrlTab}MatrOpr={idOperatore}&UserAuthKey={authKey}";
return answ;
}
}
}
}