@page "/patient/dashboard" @attribute [Authorize(Roles = UserRoles.Patient)] @layout PatientLayout @inject IAuthenticationService AuthenticationService @inject IPatientManagementService PatientManagementService @inject NavigationManager NavigationManager

Dashboard

@if (errorMessage != string.Empty) { } @if (username != null) {

Welcome, @username!

Here you have listed your active appointments.

} @if (appointments != null && appointments.Count > 0) { @foreach (var appointment in appointments) { foreach (var appointmentTime in appointment.AppointmentsList) { } }
Doctor Time Actions
Dr. @doctors[Guid.Parse(appointment.DoctorId)] @appointmentTime.ToString("g")
} else if (errorMessage == string.Empty) {

No appointments exist.

} @code { private string username; private List appointments = new(); private Dictionary doctors = new(); private string errorMessage = string.Empty; protected override async Task OnInitializedAsync() { try { var userInfo = await AuthenticationService.GetUserInformation(); username = userInfo.Name; appointments = await PatientManagementService.GetAppointmentsAsync(userInfo.Id); var allDoctors = await PatientManagementService.GetAllDoctorsAsync(); doctors = allDoctors.ToDictionary(doc => doc.Id, doc => doc.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 PatientManagementService.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}"; } } }