@page "/patient/profile" @attribute [Authorize(Roles = UserRoles.Patient)] @layout PatientLayout @inject NavigationManager Navigation @inject IPatientManagementService PatientManagementService @inject IAuthenticationService AuthenticationService

Profile

@if (!string.IsNullOrEmpty(updateMessage)) {
@updateMessage
}
Update Profile
@if (!string.IsNullOrEmpty(deleteMessage)) {
@deleteMessage
}
@code { private Patient profileModel = new(); private string updateMessage = string.Empty; private string deleteMessage = string.Empty; protected override async Task OnInitializedAsync() { var userInfo = await AuthenticationService.GetUserInformation(); if (userInfo != null) { profileModel = await PatientManagementService.GetPatientProfileAsync(userInfo.Id); } } private async Task UpdateProfile() { updateMessage = string.Empty; var success = await PatientManagementService.UpdatePatientProfileAsync(profileModel); if (success) { Navigation.NavigateTo("/dashboard/patient", true); } else { updateMessage = "An error occurred while updating your profile. Please try again."; } } private async Task DeleteAccount() { deleteMessage = string.Empty; var success = await PatientManagementService.DeletePatientProfileAsync(profileModel.Id); if (success) { await AuthenticationService.RemoveAuthToken(); Navigation.NavigateTo("/goodbye"); } else { deleteMessage = "An error occurred while deleting your account. Please try again."; } } }