127 lines
3.6 KiB
Plaintext
127 lines
3.6 KiB
Plaintext
@page "/admin/users"
|
|
@inject IAdminManagementService AdminManagementService
|
|
@inject IJSRuntime JsRuntime
|
|
|
|
@layout AdminLayout
|
|
@attribute [Authorize(Roles = UserRoles.Admin)]
|
|
|
|
<h3>User Management Page</h3>
|
|
|
|
@if (_doctors == null || _patients == null)
|
|
{
|
|
<p>
|
|
<em>Loading...</em>
|
|
</p>
|
|
}
|
|
else
|
|
{
|
|
<div class="row">
|
|
<div class="col">
|
|
<h4>Doctors</h4>
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Email</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var doctor in _doctors)
|
|
{
|
|
<tr>
|
|
<td>@doctor.Name</td>
|
|
<td>@doctor.Email</td>
|
|
<td>
|
|
<button class="btn btn-danger" @onclick="() => DeleteDoctor(doctor.Id)">Delete</button>
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="col">
|
|
<h4>Patients</h4>
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Email</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var patient in _patients)
|
|
{
|
|
<tr>
|
|
<td>@patient.Name</td>
|
|
<td>@patient.Email</td>
|
|
<td>
|
|
<button class="btn btn-danger" @onclick="() => DeletePatient(patient.Id)">Delete</button>
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
private List<Doctor> _doctors = [];
|
|
private List<Patient> _patients = [];
|
|
private string _errorMessage = string.Empty;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
var doctorsResult = await AdminManagementService.GetDoctors();
|
|
var patientsResult = await AdminManagementService.GetPatients();
|
|
|
|
_doctors = doctorsResult.Data;
|
|
_patients = patientsResult.Data;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_errorMessage = $"Error loading data: {ex.Message}";
|
|
}
|
|
}
|
|
|
|
private async Task DeleteDoctor(Guid id)
|
|
{
|
|
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Are you sure you want to delete this doctor?");
|
|
if (confirmed)
|
|
{
|
|
var success = await AdminManagementService.DeleteDoctor(id);
|
|
if (success)
|
|
{
|
|
var doctorsResult = await AdminManagementService.GetDoctors();
|
|
_doctors = doctorsResult.Data;
|
|
}
|
|
else
|
|
{
|
|
_errorMessage = "Error deleting doctor.";
|
|
}
|
|
}
|
|
}
|
|
|
|
private async Task DeletePatient(Guid id)
|
|
{
|
|
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Are you sure you want to delete this patient?");
|
|
if (confirmed)
|
|
{
|
|
var success = await AdminManagementService.DeletePatient(id);
|
|
if (success)
|
|
{
|
|
var patientsResult = await AdminManagementService.GetPatients();
|
|
_patients = patientsResult.Data;
|
|
}
|
|
else
|
|
{
|
|
_errorMessage = "Error deleting patient.";
|
|
}
|
|
}
|
|
}
|
|
|
|
} |