92 lines
2.8 KiB
Plaintext
92 lines
2.8 KiB
Plaintext
@page "/patient/profile"
|
|
@attribute [Authorize(Roles = UserRoles.Patient)]
|
|
@layout PatientLayout
|
|
@inject NavigationManager Navigation
|
|
@inject IPatientManagementService PatientManagementService
|
|
@inject IAuthenticationService AuthenticationService
|
|
|
|
<h3>Profile</h3>
|
|
|
|
@if (!string.IsNullOrEmpty(updateMessage))
|
|
{
|
|
<div class="alert alert-danger mt-3">@updateMessage</div>
|
|
}
|
|
|
|
<div class="card mt-4">
|
|
<div class="card-header">
|
|
Update Profile
|
|
</div>
|
|
<div class="card-body">
|
|
<EditForm Model="profileModel" OnValidSubmit="UpdateProfile">
|
|
<div class="form-group">
|
|
<label for="name">Name</label>
|
|
<InputText id="name" class="form-control" @bind-Value="profileModel.Name"/>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="email">Email</label>
|
|
<InputText id="email" class="form-control" @bind-Value="profileModel.Email"/>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password">Password</label>
|
|
<InputText id="password" type="password" class="form-control" @bind-Value="profileModel.Password"/>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Save Changes</button>
|
|
</EditForm>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mt-4">
|
|
<button class="btn btn-danger" @onclick="DeleteAccount">Delete Account</button>
|
|
|
|
@if (!string.IsNullOrEmpty(deleteMessage))
|
|
{
|
|
<div class="alert alert-danger mt-3">@deleteMessage</div>
|
|
}
|
|
</div>
|
|
|
|
@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.";
|
|
}
|
|
}
|
|
|
|
} |