@page "/doctor/dashboard" @attribute [Authorize(Roles = UserRoles.Doctor)] @layout DoctorLayout @inject IAuthenticationService AuthenticationService @inject IDoctorManagementService DoctorManagementService @inject NavigationManager NavigationManager

Dashboard

@if (!string.IsNullOrEmpty(errorMessage)) { } @if (!string.IsNullOrEmpty(username)) {

Welcome, Dr. @username!

Here you have listed your active appointments with patients.

} @if (appointments != null && appointments.Count > 0) { @foreach (var appointment in appointments) { foreach (var appointmentTime in appointment.AppointmentsList) { } }
Patient Time Actions
@patients[Guid.Parse(appointment.PatientId)] @appointmentTime.ToString("g")
} else if (string.IsNullOrEmpty(errorMessage)) {

No appointments exist.

} @code { private string username; private List appointments = new(); private Dictionary patients = new(); private string errorMessage = string.Empty; protected override async Task OnInitializedAsync() { try { var userInfo = await AuthenticationService.GetUserInformation(); username = userInfo.Name; appointments = await DoctorManagementService.GetAppointmentsAsync(userInfo.Id); var allPatients = await DoctorManagementService.GetAllPatientsAsync(); patients = allPatients.ToDictionary(pat => pat.Id, pat => pat.Name); if (!appointments.Any()) { errorMessage = "No appointments exist."; } } catch (Exception ex) { errorMessage = $"Failed to load data: {ex.Message}"; } } private async Task DeleteAppointment(Appointment appointment, DateTime appointmentTime) { try { var success = await DoctorManagementService.CancelAppointmentAsync( Guid.Parse(appointment.DoctorId), Guid.Parse(appointment.PatientId), appointmentTime ); if (success) { var appList = appointments.FirstOrDefault(a => a.Id == appointment.Id)?.AppointmentsList; if (appList != null) { appList.Remove(appointmentTime); if (!appList.Any()) { appointments.Remove(appointment); } } if (!appointments.Any()) { errorMessage = "No appointments exist."; } } else { errorMessage = "Failed to delete the appointment."; } StateHasChanged(); } catch (Exception ex) { errorMessage = $"Error deleting appointment: {ex.Message}"; } } }