diff --git a/FIT5032-Assignment/Controllers/AppointmentsController.cs b/FIT5032-Assignment/Controllers/AppointmentsController.cs index 211a55f..bb5d7bc 100644 --- a/FIT5032-Assignment/Controllers/AppointmentsController.cs +++ b/FIT5032-Assignment/Controllers/AppointmentsController.cs @@ -93,6 +93,39 @@ namespace FIT5032_Assignment.Controllers { // GET: Appointments public ActionResult Index() { + // Check login + if (Request.Cookies["psg_auth_token"] == null) { + // Redirect to home page + return RedirectToAction("Index"); + } + var user = psgCredentialVerify(Request.Cookies["psg_auth_token"].Value); + if (user == null) { + // Redirect to home page + Response.Cookies["psg_auth_token"].Expires = DateTime.Now.AddDays(-1); + return RedirectToAction("Index"); + } + var userProfile = loginInfo(user); + if (userProfile == null) { + // Redirect to home page, and remove cookies + Response.Cookies["psg_auth_token"].Expires = DateTime.Now.AddDays(-1); + return RedirectToAction("Index"); + } + // Detect user role + ViewBag.role = db.Users.Find(userProfile.uuid).role; + + var appointments = new List>(); + if (userProfile.role == 1) { // patient + var dbData = db.Appointments.Where(a => a.patient == userProfile.uuid).OrderByDescending(a => a.createdAt).ToList(); + foreach (var item in dbData) { + appointments.Add(new Tuple(item, db.Users.Find(item.responsibleBy))); + } + } else if (userProfile.role == 2) { // doctor + var dbData = db.Appointments.Where(a => a.responsibleBy == userProfile.uuid).OrderByDescending(a => a.createdAt).ToList(); + foreach (var item in dbData) { + appointments.Add(new Tuple(item, db.Users.Find(item.patient))); + } + } + ViewBag.appointments = appointments; ViewBag.tip = TempData["tip"]; return View(); } diff --git a/FIT5032-Assignment/Controllers/HomeController.cs b/FIT5032-Assignment/Controllers/HomeController.cs index f8ed69a..04b3f9e 100644 --- a/FIT5032-Assignment/Controllers/HomeController.cs +++ b/FIT5032-Assignment/Controllers/HomeController.cs @@ -168,6 +168,10 @@ namespace FIT5032_Assignment.Controllers { ViewBag.role = dbUser.First().role == 1 ? "Patient" : "Doctor"; } } + } else { + // Remove cookies and refresh page + Response.Cookies["psg_auth_token"].Expires = DateTime.Now.AddDays(-1); + return RedirectToAction("Index"); } } return View(); diff --git a/FIT5032-Assignment/Views/Appointments/Index.cshtml b/FIT5032-Assignment/Views/Appointments/Index.cshtml index 0de5b2d..a73fcbe 100644 --- a/FIT5032-Assignment/Views/Appointments/Index.cshtml +++ b/FIT5032-Assignment/Views/Appointments/Index.cshtml @@ -1,7 +1,7 @@  @{ - ViewBag.Title = "Appointments"; - Layout = "~/Views/Shared/_Layout.cshtml"; + ViewBag.Title = "Appointments"; + Layout = "~/Views/Shared/_Layout.cshtml"; } @if (ViewBag.tip != null) { @@ -10,8 +10,137 @@ } -

Appointments

+
+

My appointments

+ @if (ViewBag.role == 1) {Make a new appointment} +
- \ No newline at end of file +@if (ViewBag.role == 1) { + + + + + + + + @foreach (var item in ViewBag.appointments) { + + + + + + + } +
DoctorAppointment dateStatusActions
+
+ + @item.Item2.displayName +
+
@item.Item1.appointmentDate + @if (item.Item1.status == 0) { + Pending + } else if (item.Item1.status == 1) { + Waiting for serve + } else if (item.Item1.status == -1) { + Cancelled + } else if (item.Item1.status == 2) { + Completed + } else { + Unknown + } + + @if (item.Item1.status == 0) { + + } +
+} else if (ViewBag.role == 2) { + + + + + + + + @foreach (var item in ViewBag.appointments) { + + + + + + + } +
PatientAppointment dateStatusActions
+
+ + @item.Item2.displayName +
+
@item.Item1.appointmentDate + @if (item.Item1.status == 0) { + Pending + } else if (item.Item1.status == 1) { + Waiting for serve + } else if (item.Item1.status == -1) { + Cancelled + } else if (item.Item1.status == 2) { + Completed + } else { + Unknown + } + + @if (item.Item1.status == 0) { + + + } +
+} + +@section Scripts { + +} \ No newline at end of file