List appointments
This commit is contained in:
		
							parent
							
								
									c3c09f8966
								
							
						
					
					
						commit
						12530059ee
					
				| 
						 | 
					@ -93,6 +93,39 @@ namespace FIT5032_Assignment.Controllers {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // GET: Appointments
 | 
					    // GET: Appointments
 | 
				
			||||||
    public ActionResult Index() {
 | 
					    public ActionResult Index() {
 | 
				
			||||||
 | 
					      // 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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      var appointments = new List<Tuple<Appointments, Users>>();
 | 
				
			||||||
 | 
					      if (userProfile.role == 1) { // patient
 | 
				
			||||||
 | 
					        var dbData = db.Appointments.Where(a => a.patient == userProfile.uuid).OrderByDescending(a => a.createdAt).ToList();
 | 
				
			||||||
 | 
					        foreach (var item in dbData) {
 | 
				
			||||||
 | 
					          appointments.Add(new Tuple<Appointments, Users>(item, db.Users.Find(item.responsibleBy)));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      } else if (userProfile.role == 2) { // doctor
 | 
				
			||||||
 | 
					        var dbData = db.Appointments.Where(a => a.responsibleBy == userProfile.uuid).OrderByDescending(a => a.createdAt).ToList();
 | 
				
			||||||
 | 
					        foreach (var item in dbData) {
 | 
				
			||||||
 | 
					          appointments.Add(new Tuple<Appointments, Users>(item, db.Users.Find(item.patient)));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      ViewBag.appointments = appointments;
 | 
				
			||||||
      ViewBag.tip = TempData["tip"];
 | 
					      ViewBag.tip = TempData["tip"];
 | 
				
			||||||
      return View();
 | 
					      return View();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -168,6 +168,10 @@ namespace FIT5032_Assignment.Controllers {
 | 
				
			||||||
              ViewBag.role = dbUser.First().role == 1 ? "Patient" : "Doctor";
 | 
					              ViewBag.role = dbUser.First().role == 1 ? "Patient" : "Doctor";
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          // Remove cookies and refresh page
 | 
				
			||||||
 | 
					          Response.Cookies["psg_auth_token"].Expires = DateTime.Now.AddDays(-1);
 | 
				
			||||||
 | 
					          return RedirectToAction("Index");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      return View();
 | 
					      return View();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@{
 | 
					@{
 | 
				
			||||||
    ViewBag.Title = "Appointments";
 | 
					  ViewBag.Title = "Appointments";
 | 
				
			||||||
    Layout = "~/Views/Shared/_Layout.cshtml";
 | 
					  Layout = "~/Views/Shared/_Layout.cshtml";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@if (ViewBag.tip != null) {
 | 
					@if (ViewBag.tip != null) {
 | 
				
			||||||
| 
						 | 
					@ -10,8 +10,137 @@
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<h2>Appointments</h2>
 | 
					<div class="titlebar">
 | 
				
			||||||
 | 
					  <h2>My appointments</h2>
 | 
				
			||||||
 | 
					  @if (ViewBag.role == 1) {<a href="./Create" class="btn btn-primary">Make a new appointment</a>}
 | 
				
			||||||
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<ul>
 | 
					@if (ViewBag.role == 1) {
 | 
				
			||||||
  <li><a href="./Create">Make a new appointment</a></li>
 | 
					  <table class="table table-hover">
 | 
				
			||||||
</ul>
 | 
					    <tr>
 | 
				
			||||||
 | 
					      <th>Doctor</th>
 | 
				
			||||||
 | 
					      <th>Appointment date</th>
 | 
				
			||||||
 | 
					      <th>Status</th>
 | 
				
			||||||
 | 
					      <th>Actions</th>
 | 
				
			||||||
 | 
					    </tr>
 | 
				
			||||||
 | 
					    @foreach (var item in ViewBag.appointments) {
 | 
				
			||||||
 | 
					      <tr>
 | 
				
			||||||
 | 
					        <td>
 | 
				
			||||||
 | 
					          <div class="userprofile">
 | 
				
			||||||
 | 
					            <img src='@item.Item2.avatar' class="avatar" />
 | 
				
			||||||
 | 
					            <span class="displaname">@item.Item2.displayName</span>
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
 | 
					        </td>
 | 
				
			||||||
 | 
					        <td>@item.Item1.appointmentDate</td>
 | 
				
			||||||
 | 
					        <td>
 | 
				
			||||||
 | 
					          @if (item.Item1.status == 0) {
 | 
				
			||||||
 | 
					            <span class="badge badge-warning">Pending</span>
 | 
				
			||||||
 | 
					          } else if (item.Item1.status == 1) {
 | 
				
			||||||
 | 
					            <span class="badge badge-info">Waiting for serve</span>
 | 
				
			||||||
 | 
					          } else if (item.Item1.status == -1) {
 | 
				
			||||||
 | 
					            <span class="badge badge-secondary">Cancelled</span>
 | 
				
			||||||
 | 
					          } else if (item.Item1.status == 2) {
 | 
				
			||||||
 | 
					            <span class="badge badge-info">Completed</span>
 | 
				
			||||||
 | 
					          } else {
 | 
				
			||||||
 | 
					            <span class="badge badge-secondary">Unknown</span>
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        </td>
 | 
				
			||||||
 | 
					        <td>
 | 
				
			||||||
 | 
					          @if (item.Item1.status == 0) {
 | 
				
			||||||
 | 
					            <button class="btn btn-sm btn-danger">Cancel</button>
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        </td>
 | 
				
			||||||
 | 
					      </tr>
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  </table>
 | 
				
			||||||
 | 
					} else if (ViewBag.role == 2) {
 | 
				
			||||||
 | 
					  <table class="table table-hover">
 | 
				
			||||||
 | 
					    <tr>
 | 
				
			||||||
 | 
					      <th>Patient</th>
 | 
				
			||||||
 | 
					      <th>Appointment date</th>
 | 
				
			||||||
 | 
					      <th>Status</th>
 | 
				
			||||||
 | 
					      <th>Actions</th>
 | 
				
			||||||
 | 
					    </tr>
 | 
				
			||||||
 | 
					    @foreach (var item in ViewBag.appointments) {
 | 
				
			||||||
 | 
					      <tr>
 | 
				
			||||||
 | 
					        <td>
 | 
				
			||||||
 | 
					          <div class="userprofile">
 | 
				
			||||||
 | 
					            <img src='@item.Item2.avatar' class="avatar" />
 | 
				
			||||||
 | 
					            <span class="displaname">@item.Item2.displayName</span>
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
 | 
					        </td>
 | 
				
			||||||
 | 
					        <td>@item.Item1.appointmentDate</td>
 | 
				
			||||||
 | 
					        <td>
 | 
				
			||||||
 | 
					          @if (item.Item1.status == 0) {
 | 
				
			||||||
 | 
					            <span class="badge badge-warning">Pending</span>
 | 
				
			||||||
 | 
					          } else if (item.Item1.status == 1) {
 | 
				
			||||||
 | 
					            <span class="badge badge-info">Waiting for serve</span>
 | 
				
			||||||
 | 
					          } else if (item.Item1.status == -1) {
 | 
				
			||||||
 | 
					            <span class="badge badge-secondary">Cancelled</span>
 | 
				
			||||||
 | 
					          } else if (item.Item1.status == 2) {
 | 
				
			||||||
 | 
					            <span class="badge badge-info">Completed</span>
 | 
				
			||||||
 | 
					          } else {
 | 
				
			||||||
 | 
					            <span class="badge badge-secondary">Unknown</span>
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        </td>
 | 
				
			||||||
 | 
					        <td>
 | 
				
			||||||
 | 
					          @if (item.Item1.status == 0) {
 | 
				
			||||||
 | 
					            <button class="btn btn-sm btn-primary">Approve</button>
 | 
				
			||||||
 | 
					            <button class="btn btn-sm btn-danger">Cancel</button>
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        </td>
 | 
				
			||||||
 | 
					      </tr>
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  </table>
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@section Scripts {
 | 
				
			||||||
 | 
					  <style>
 | 
				
			||||||
 | 
					    .titlebar {
 | 
				
			||||||
 | 
					      display: flex;
 | 
				
			||||||
 | 
					      justify-content: space-between;
 | 
				
			||||||
 | 
					      align-items: center;
 | 
				
			||||||
 | 
					      margin-bottom: 20px;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .badge {
 | 
				
			||||||
 | 
					      border-radius: 0.25rem;
 | 
				
			||||||
 | 
					      border-width: 1px;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .badge-warning {
 | 
				
			||||||
 | 
					      background-color: #ffc107;
 | 
				
			||||||
 | 
					      border-color: #ffc107;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .badge-success {
 | 
				
			||||||
 | 
					      background-color: #28a745;
 | 
				
			||||||
 | 
					      border-color: #28a745;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .badge-danger {
 | 
				
			||||||
 | 
					      background-color: #dc3545;
 | 
				
			||||||
 | 
					      border-color: #dc3545;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .badge-info {
 | 
				
			||||||
 | 
					      background-color: #17a2b8;
 | 
				
			||||||
 | 
					      border-color: #17a2b8;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .badge-secondary {
 | 
				
			||||||
 | 
					      background-color: #6c757d;
 | 
				
			||||||
 | 
					      border-color: #6c757d;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .userprofile .displaname {
 | 
				
			||||||
 | 
					      margin-left: 10px;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .userprofile .avatar {
 | 
				
			||||||
 | 
					      width: 30px;
 | 
				
			||||||
 | 
					      height: 30px;
 | 
				
			||||||
 | 
					      border-radius: 50%;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  </style>
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user