@page "/doctor/profile"
@attribute [Authorize(Roles = UserRoles.Doctor)]
@layout DoctorLayout
@inject NavigationManager Navigation
@inject IDoctorManagementService DoctorManagementService
@inject IAuthenticationService AuthenticationService
Profile
@if (!string.IsNullOrEmpty(updateMessage))
{
@updateMessage
}
@if (!string.IsNullOrEmpty(deleteMessage))
{
@deleteMessage
}
@code {
private Doctor profileModel = new();
private string updateMessage = string.Empty;
private string deleteMessage = string.Empty;
private bool updateSuccess;
private bool deleteSuccess;
protected override async Task OnInitializedAsync()
{
var userInfo = await AuthenticationService.GetUserInformation();
if (userInfo != null)
{
profileModel = await DoctorManagementService.GetDoctorProfileAsync(userInfo.Id);
}
}
private async Task UpdateProfile()
{
updateMessage = string.Empty;
updateSuccess = false;
var success = await DoctorManagementService.UpdateDoctorProfileAsync(profileModel);
if (success)
{
updateMessage = "Profile updated successfully.";
updateSuccess = true;
}
else
{
updateMessage = "An error occurred while updating your profile. Please try again.";
updateSuccess = false;
}
}
private async Task DeleteAccount()
{
deleteMessage = string.Empty;
deleteSuccess = false;
var success = await DoctorManagementService.DeleteDoctorProfileAsync(profileModel.Id);
if (success)
{
await AuthenticationService.RemoveAuthToken();
Navigation.NavigateTo("/goodbye");
}
else
{
deleteMessage = "An error occurred while deleting your account. Please try again.";
deleteSuccess = false;
}
}
}