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 }