Submit review
This commit is contained in:
parent
46c50901e8
commit
9654264773
|
@ -633,5 +633,90 @@ namespace FIT5032_Assignment.Controllers {
|
|||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Review(FormCollection collection) {
|
||||
Trace.WriteLine(collection["appointment"]);
|
||||
|
||||
// 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", "Home");
|
||||
}
|
||||
|
||||
// Detect if user logined is patient
|
||||
var role = db.Users.Find(userProfile.uuid).role;
|
||||
if (role != 1) {
|
||||
// Redirect to home page
|
||||
TempData["tip"] = "Operation invalid";
|
||||
return Redirect("/Appointments/Index");
|
||||
}
|
||||
|
||||
// Check if the appointment is belong to the doctor or patient
|
||||
var appointment = db.Appointments.Find(collection["appointment"]);
|
||||
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");
|
||||
}
|
||||
|
||||
// Check if the review exist
|
||||
try {
|
||||
var review = db.Reviews.Find(collection["appointment"]);
|
||||
Trace.WriteLine(review);
|
||||
if (review != null) {
|
||||
TempData["tip"] = "You cannot append a new review to this appointment.";
|
||||
return Redirect("/Appointments/Index");
|
||||
}
|
||||
} catch(Exception e) {
|
||||
Trace.WriteLine(e);
|
||||
TempData["tip"] = "System error";
|
||||
return Redirect("/Appointments/Index");
|
||||
}
|
||||
|
||||
// Create review
|
||||
var uuid = Guid.NewGuid().ToString();
|
||||
Reviews newReview = new Reviews {
|
||||
appointment = collection["appointment"],
|
||||
patient = userProfile.uuid,
|
||||
doctor = appointment.responsibleBy,
|
||||
score = Convert.ToInt32(collection["score"]),
|
||||
comment = collection["comment"],
|
||||
reviewAt = DateTime.Now,
|
||||
};
|
||||
db.Reviews.Add(newReview);
|
||||
db.SaveChanges();
|
||||
|
||||
ViewBag.role = role;
|
||||
ViewBag.appointment = appointment;
|
||||
ViewBag.doctor = db.Doctors.Where(d => d.user == appointment.responsibleBy);
|
||||
ViewBag.doctorUser = db.Users.Find(appointment.responsibleBy);
|
||||
ViewBag.patient = db.Users.Find(appointment.patient);
|
||||
ViewBag.review = newReview;
|
||||
ViewBag.reviewAvailable = true;
|
||||
ViewBag.tip = "Thanks for submit your review!";
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,18 @@
|
|||
Layout = "~/Views/Shared/_Layout.cshtml";
|
||||
}
|
||||
|
||||
@if (ViewBag.tip != null) {
|
||||
<div class="alert alert-success" role="alert">
|
||||
@ViewBag.tip
|
||||
</div>
|
||||
}
|
||||
|
||||
<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">
|
||||
<input type="hidden" id="appointment" name="appointment" required value="@ViewBag.appointment.uuid" />
|
||||
<div class="form-group">
|
||||
<label for="score">How about your experience?</label>
|
||||
<input type="hidden" id="score" name="score" required />
|
||||
|
@ -26,7 +33,7 @@
|
|||
<div class="form-group">
|
||||
<label for="comment">Leave your comment</label>
|
||||
<div class='input-group'>
|
||||
<textarea id="comment" class="form-control" name="comment" ></textarea>
|
||||
<textarea id="comment" class="form-control" name="comment"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="submit">Submit</button>
|
||||
|
@ -39,6 +46,7 @@
|
|||
.material-symbols-outlined {
|
||||
font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24
|
||||
}
|
||||
|
||||
textarea {
|
||||
width: 100%;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user