Leave review for appointment
This commit is contained in:
parent
7da2697088
commit
46c50901e8
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ namespace FIT5032_Assignment.Controllers {
|
|||
public DbSet<Doctors> Doctors { get; set; }
|
||||
public DbSet<Appointments> Appointments { get; set; }
|
||||
public DbSet<Images> Images { get; set; }
|
||||
public DbSet<Reviews> Reviews { get; set; }
|
||||
}
|
||||
public class HomeController : Controller {
|
||||
public static string GetMd5Hash(string input) {
|
||||
|
|
|
@ -325,6 +325,7 @@
|
|||
<Content Include="Views\Appointments\Create.cshtml" />
|
||||
<Content Include="Views\Appointments\UploadImage.cshtml" />
|
||||
<Content Include="Views\Appointments\Detail.cshtml" />
|
||||
<Content Include="Views\Appointments\Review.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\upload_images\" />
|
||||
|
|
66
FIT5032-Assignment/Views/Appointments/Review.cshtml
Normal file
66
FIT5032-Assignment/Views/Appointments/Review.cshtml
Normal file
|
@ -0,0 +1,66 @@
|
|||
|
||||
@{
|
||||
ViewBag.Title = "Review";
|
||||
Layout = "~/Views/Shared/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<h2>Rate the experience</h2>
|
||||
|
||||
@if (ViewBag.role == 1) {
|
||||
<p>You are about to review the Doctor <b>@ViewBag.doctorUser.displayName</b></p>
|
||||
<form method="post">
|
||||
<div class="form-group">
|
||||
<label for="score">How about your experience?</label>
|
||||
<input type="hidden" id="score" name="score" required />
|
||||
<button class="btn btn-light" id="btn-good" onClick="rate(1)" type="button">
|
||||
<span class="material-symbols-outlined">
|
||||
thumb_up
|
||||
</span>
|
||||
</button>
|
||||
<button class="btn btn-light" id="btn-bad" onClick="rate(0)" type="button">
|
||||
<span class="material-symbols-outlined">
|
||||
thumb_down
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="comment">Leave your comment</label>
|
||||
<div class='input-group'>
|
||||
<textarea id="comment" class="form-control" name="comment" ></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="submit">Submit</button>
|
||||
</form>
|
||||
}
|
||||
|
||||
@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")
|
||||
<style>
|
||||
.material-symbols-outlined {
|
||||
font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24
|
||||
}
|
||||
textarea {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function rate(score) {
|
||||
$("#score").val(score)
|
||||
if (score == 1) {
|
||||
$("#btn-good").removeClass("btn-light")
|
||||
$("#btn-good").addClass("btn-success")
|
||||
$("#btn-bad").removeClass("btn-danger")
|
||||
$("#btn-bad").addClass("btn-light")
|
||||
} else {
|
||||
$("#btn-good").removeClass("btn-success")
|
||||
$("#btn-good").addClass("btn-light")
|
||||
$("#btn-bad").removeClass("btn-light")
|
||||
$("#btn-bad").addClass("btn-danger")
|
||||
}
|
||||
}
|
||||
|
||||
if (@ViewBag.reviewAvailable === "True") {
|
||||
alert("Review available")
|
||||
}
|
||||
</script>
|
||||
}
|
Loading…
Reference in New Issue
Block a user