From 30c3fbcadc472d94d007efae23bf6b59e134e678 Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Thu, 19 Oct 2023 11:28:24 +1100 Subject: [PATCH] Image read --- FIT5032-Assignment/App_Start/RouteConfig.cs | 6 + .../Controllers/AppointmentsController.cs | 48 +++++++ .../Controllers/HomeController.cs | 2 + FIT5032-Assignment/Controllers/System.cs | 21 ++++ FIT5032-Assignment/FIT5032-Assignment.csproj | 3 + .../FIT5032-Assignment.csproj.user | 2 +- .../Views/Appointments/Detail.cshtml | 118 ++++++++++++++++++ .../Views/Appointments/Index.cshtml | 2 + 8 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 FIT5032-Assignment/Controllers/System.cs create mode 100644 FIT5032-Assignment/Views/Appointments/Detail.cshtml diff --git a/FIT5032-Assignment/App_Start/RouteConfig.cs b/FIT5032-Assignment/App_Start/RouteConfig.cs index 5900e43..2f0da7f 100644 --- a/FIT5032-Assignment/App_Start/RouteConfig.cs +++ b/FIT5032-Assignment/App_Start/RouteConfig.cs @@ -28,6 +28,12 @@ namespace FIT5032_Assignment { url: "Appointments", defaults: new { controller = "Appointments", action = "Index", id = UrlParameter.Optional } ); + + routes.MapRoute( + name: "System", + url: "System/{action}/{id}", + defaults: new { controller = "System", action = "GetUploadedImage", id = UrlParameter.Optional } + ); } } } diff --git a/FIT5032-Assignment/Controllers/AppointmentsController.cs b/FIT5032-Assignment/Controllers/AppointmentsController.cs index c4c3150..23cfd0a 100644 --- a/FIT5032-Assignment/Controllers/AppointmentsController.cs +++ b/FIT5032-Assignment/Controllers/AppointmentsController.cs @@ -520,5 +520,53 @@ namespace FIT5032_Assignment.Controllers { return Redirect("/Appointments/Index"); } } + + public ActionResult Detail(string id) { + // Verify 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; + + // 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"); + } + + 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 images + var image = db.Images.Where(i => i.appointment == id).First(); + ViewBag.image = image; + return View(); + } } } diff --git a/FIT5032-Assignment/Controllers/HomeController.cs b/FIT5032-Assignment/Controllers/HomeController.cs index 4710316..e25560b 100644 --- a/FIT5032-Assignment/Controllers/HomeController.cs +++ b/FIT5032-Assignment/Controllers/HomeController.cs @@ -412,6 +412,8 @@ namespace FIT5032_Assignment.Controllers { return new HttpStatusCodeResult(HttpStatusCode.BadGateway); } } + + } } \ No newline at end of file diff --git a/FIT5032-Assignment/Controllers/System.cs b/FIT5032-Assignment/Controllers/System.cs new file mode 100644 index 0000000..5fc324b --- /dev/null +++ b/FIT5032-Assignment/Controllers/System.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using System.IO; + +namespace FIT5032_Assignment.Controllers { + public class SystemController : Controller { + // GET: System + public ActionResult GetUploadedImage(string fileName) { + var filePath = Server.MapPath("~/App_Data/upload_images/" + fileName); + if (!System.IO.File.Exists(filePath)) { + return HttpNotFound(); + } + var fileContent = System.IO.File.ReadAllText(filePath); + var contentType = MimeMapping.GetMimeMapping(fileName); + return File(fileContent, contentType); + } + } +} \ No newline at end of file diff --git a/FIT5032-Assignment/FIT5032-Assignment.csproj b/FIT5032-Assignment/FIT5032-Assignment.csproj index 3bfe2bc..4bd3523 100644 --- a/FIT5032-Assignment/FIT5032-Assignment.csproj +++ b/FIT5032-Assignment/FIT5032-Assignment.csproj @@ -186,6 +186,7 @@ + Global.asax @@ -323,10 +324,12 @@ + + diff --git a/FIT5032-Assignment/FIT5032-Assignment.csproj.user b/FIT5032-Assignment/FIT5032-Assignment.csproj.user index 48d35fd..80bcb70 100644 --- a/FIT5032-Assignment/FIT5032-Assignment.csproj.user +++ b/FIT5032-Assignment/FIT5032-Assignment.csproj.user @@ -9,7 +9,7 @@ Debug|Any CPU - MvcControllerWithActionsScaffolder + MvcControllerEmptyScaffolder root/Common/MVC/Controller 600 ~/Views/Shared/_Layout.cshtml diff --git a/FIT5032-Assignment/Views/Appointments/Detail.cshtml b/FIT5032-Assignment/Views/Appointments/Detail.cshtml new file mode 100644 index 0000000..b718131 --- /dev/null +++ b/FIT5032-Assignment/Views/Appointments/Detail.cshtml @@ -0,0 +1,118 @@ + +@{ + ViewBag.Title = "Detail"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} + +

Appointment detail

+ +
+
Appointment date
+
@ViewBag.appointment.appointmentDate
+
+ +
+
Doctor
+
+ + @ViewBag.doctorUser.displayName +
+
+ +
+
Patient
+
+ + @ViewBag.patient.displayName +
+
+ +
+
Status
+
+ @if(ViewBag.appointment.status == 0) { + Pending + } else if(ViewBag.appointment.status == 1) { + Waiting for serve + } else if(ViewBag.appointment.status == -1) { + Cancelled + } else if(ViewBag.appointment.status == 2) { + Completed + } else { + Unknown + } +
+
+ +@if(ViewBag.appointment.status == 2) { +
+
Attached image
+
+ +
+
+} + +@section Scripts { + +} \ No newline at end of file diff --git a/FIT5032-Assignment/Views/Appointments/Index.cshtml b/FIT5032-Assignment/Views/Appointments/Index.cshtml index c562a18..3d9e873 100644 --- a/FIT5032-Assignment/Views/Appointments/Index.cshtml +++ b/FIT5032-Assignment/Views/Appointments/Index.cshtml @@ -89,6 +89,8 @@ Cancel } else if (item.Item1.status == 1) { Upload Image + } else if (item.Item1.status == 2) { + Detail }