Files
FACULTATE-HEALTHCARE_MANAGER/frontend/UI/Pages/Doctor/DoctorProfile.razor
T
2024-05-30 15:40:13 +03:00

107 lines
3.5 KiB
Plaintext

@page "/doctor/profile"
@attribute [Authorize(Roles = UserRoles.Doctor)]
@layout DoctorLayout
@inject NavigationManager Navigation
@inject IDoctorManagementService DoctorManagementService
@inject IAuthenticationService AuthenticationService
<h3>Profile</h3>
@if (!string.IsNullOrEmpty(updateMessage))
{
<div class="alert @(updateSuccess ? "alert-success" : "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-row">
<div class="form-group col-md-6">
<label for="name">Name</label>
<InputText id="name" class="form-control" @bind-Value="profileModel.Name"/>
</div>
<div class="form-group col-md-6">
<label for="email">Email</label>
<InputText id="email" class="form-control" @bind-Value="profileModel.Email"/>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="password">Password</label>
<InputText id="password" type="password" class="form-control" @bind-Value="profileModel.Password"/>
</div>
<div class="form-group col-md-6">
<label for="description">Description</label>
<InputTextArea id="description" class="form-control" @bind-Value="profileModel.Description" rows="5"/>
</div>
</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 @(deleteSuccess ? "alert-success" : "alert-danger") mt-3">@deleteMessage</div>
}
</div>
@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;
}
}
}