insight/src/Web/Insight.Web/Pages/Account/Profile.razor.cs
2023-09-21 18:58:32 +02:00

40 lines
No EOL
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Insight.Infrastructure.Entities;
using Insight.Infrastructure.Services;
using Insight.Web.Constants;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using MudBlazor;
namespace Insight.Web.Pages.Account;
[Route(Navigation.Account.Profile)]
public partial class Profile
{
[Parameter] public InsightUser? Account { get; set; }
[Inject] private IdentityService IdentityService { get; init; } = default!;
[Inject] private AuthenticationStateProvider AuthenticationStateProvider { get; init; } = default!;
private readonly string _title = "ProfileInsight";
private readonly List<BreadcrumbItem> _breadcrumbs = new()
{
new BreadcrumbItem("Home", href: Navigation.Home),
new BreadcrumbItem("Account", href: Navigation.Account.Profile),
new BreadcrumbItem("Profile", href: "#", true)
};
protected override async Task OnInitializedAsync()
{
await OnRefreshAsync();
}
private async Task OnRefreshAsync()
{
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (state?.User?.Identity?.Name is null) return;
Account = await IdentityService.GetByEmailAsync(state.User.Identity.Name).ConfigureAwait(false);
await InvokeAsync(StateHasChanged);
}
}