From 46c50901e8e9057271e898feb32d98e596ca7d96 Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Thu, 19 Oct 2023 15:28:03 +1100 Subject: [PATCH] Leave review for appointment --- .../Controllers/AppointmentsController.cs | 65 ++++++++++++++++++ .../Controllers/HomeController.cs | 1 + FIT5032-Assignment/FIT5032-Assignment.csproj | 1 + .../Views/Appointments/Review.cshtml | 66 +++++++++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 FIT5032-Assignment/Views/Appointments/Review.cshtml diff --git a/FIT5032-Assignment/Controllers/AppointmentsController.cs b/FIT5032-Assignment/Controllers/AppointmentsController.cs index 23cfd0a..c1635c4 100644 --- a/FIT5032-Assignment/Controllers/AppointmentsController.cs +++ b/FIT5032-Assignment/Controllers/AppointmentsController.cs @@ -568,5 +568,70 @@ namespace FIT5032_Assignment.Controllers { ViewBag.image = image; return View(); } + + public ActionResult Review(string id) { + // 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; + + // Only patient can review appointment, but doctor can view + /*if (userProfile.role != 1) { + TempData["tip"] = "This operation is not allowed."; + return Redirect("/Appointments/Index"); + } */ + + // Check if the appointment is belong to the doctor or patient + var appointment = db.Appointments.Find(id); + if (appointment == null) { + TempData["tip"] = "The appointment does not exist."; + return Redirect("/Appointments/Index"); + } + if (appointment.patient != userProfile.uuid && appointment.responsibleBy != userProfile.uuid) { + TempData["tip"] = "The appointment does not exist."; + return Redirect("/Appointments/Index"); + } + + // Check status == 2 + if (appointment.status != 2) { + TempData["tip"] = "Operation invalid"; + return Redirect("/Appointments/Index"); + } + + ViewBag.appointment = appointment; + + // Fetch doctor profile + ViewBag.doctor = db.Doctors.Where(d => d.user == appointment.responsibleBy); + ViewBag.doctorUser = db.Users.Find(appointment.responsibleBy); + + // Fetch patient profile + ViewBag.patient = db.Users.Find(appointment.patient); + + // Fetch review if exist + var review = db.Reviews.Where(r => r.appointment == id); + if (review.Count() != 0) { + ViewBag.review = review.First(); + ViewBag.reviewAvailable = true; + } else { + ViewBag.reviewAvailable = false; + } + + return View(); + } } } diff --git a/FIT5032-Assignment/Controllers/HomeController.cs b/FIT5032-Assignment/Controllers/HomeController.cs index e25560b..ef1fe3f 100644 --- a/FIT5032-Assignment/Controllers/HomeController.cs +++ b/FIT5032-Assignment/Controllers/HomeController.cs @@ -53,6 +53,7 @@ namespace FIT5032_Assignment.Controllers { public DbSet Doctors { get; set; } public DbSet Appointments { get; set; } public DbSet Images { get; set; } + public DbSet Reviews { get; set; } } public class HomeController : Controller { public static string GetMd5Hash(string input) { diff --git a/FIT5032-Assignment/FIT5032-Assignment.csproj b/FIT5032-Assignment/FIT5032-Assignment.csproj index 4bd3523..1665da3 100644 --- a/FIT5032-Assignment/FIT5032-Assignment.csproj +++ b/FIT5032-Assignment/FIT5032-Assignment.csproj @@ -325,6 +325,7 @@ + diff --git a/FIT5032-Assignment/Views/Appointments/Review.cshtml b/FIT5032-Assignment/Views/Appointments/Review.cshtml new file mode 100644 index 0000000..b1595dc --- /dev/null +++ b/FIT5032-Assignment/Views/Appointments/Review.cshtml @@ -0,0 +1,66 @@ + +@{ + ViewBag.Title = "Review"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} + +

Rate the experience

+ +@if (ViewBag.role == 1) { +

You are about to review the Doctor @ViewBag.doctorUser.displayName

+
+
+ + + + +
+
+ +
+ +
+
+ +
+} + +@section Scripts { + @Styles.Render("https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200") + + +} \ No newline at end of file