@page "/my-profile/{Role}" @using HealthcareManagerUiWebAssem.Models @using HealthcareManagerUiWebAssem.Services.Authentication @using HealthcareManagerUiWebAssem.Services.Profile @using HealthcareManagerUiWebAssem.Services.User @using HealthcareManagerUiWebAssem.Services.UserSessionInformation @layout AuthLayout @inject IUserSessionInformation UserSessionInformation; @inject IAuthenticationService AuthenticationService; @inject IProfileService ProfileService @inject UserService UserService @inject NavigationManager NavigationManager My Profile

My Profile

@if (profile != null) {
@if (Role.Equals("doctor", StringComparison.OrdinalIgnoreCase)) {
}
} @code { [SupplyParameterFromForm] public UserUpdateProfileModel? profile { get; set; } [Parameter] public string Role { get; set; } private string errorMessage; protected override async Task OnInitializedAsync() { var tokenDto = new TokenRefreshModel(await UserSessionInformation.GetTokenAsync()); var refreshResult = await AuthenticationService.RefreshToken(tokenDto); if (refreshResult.StatusCode < HttpStatusCodes.BadRequest) { NavigationManager.NavigateTo("/"); } profile ??= await UserService.InitializeProfile(Role, ProfileService); var userId = await UserSessionInformation.GetIdAsync(); } private async Task HandleUpdateProfile() { profile.Id = UserService.UserId; var response = Role switch { "doctor" => await ProfileService.UpdateDoctorProfile(profile), "patient" => await ProfileService.UpdatePatientProfile(profile), _ => null }; if (response.StatusCode >= 200 && response.StatusCode <= 299) { NavigationManager.NavigateTo($"/my-profile/{Role}"); } else { errorMessage = response?.Message ?? "An error occurred."; } } private async Task HandleDeleteProfile() { var response = Role switch { "doctor" => await ProfileService.DeleteDoctorProfile(UserService.UserId), "patient" => await ProfileService.DeletePatientProfile(UserService.UserId), _ => null }; if (response.StatusCode >= 200 && response.StatusCode <= 299) { NavigationManager.NavigateTo($"/login/{Role}"); } else { errorMessage = response?.Message ?? "An error occurred."; } } }