Compare commits

..

2 Commits

Author SHA1 Message Date
6388899f8b Find doctor 2023-10-17 18:05:39 +11:00
7c747a583e fix a problem for database has not saved changes 2023-10-17 16:10:27 +11:00
8 changed files with 185 additions and 35 deletions

View File

@ -5,20 +5,23 @@ using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace FIT5032_Assignment
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
namespace FIT5032_Assignment {
public class RouteConfig {
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Put Home folder into root route independently without keyword "Home"
routes.MapRoute(
name: "Home",
url: "{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
// Put Home folder into root route independently without keyword "Home"
routes.MapRoute(
name: "Home",
url: "{action}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Actions",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}

View File

@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Data.Entity.Core.Common.CommandTrees;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FIT5032_Assignment.Models;
using System.Data.Entity;
using System.Diagnostics;
namespace FIT5032_Assignment.Controllers {
public class AppointmentsController : Controller {
private Database1Entities db = new Database1Entities();
// GET: Appointments
public ActionResult Index() {
return View();
}
// GET: Appointments/Details/5
public ActionResult Details(int id) {
return View();
}
// GET: Appointments/Create
public ActionResult Create() {
// Pass a dropdown list for all doctors
List<Doctors> doctors = db.Doctors.ToList();
// Create a tuple for put uuid and displayName into it
List<Tuple<string, string>> doctorsList = new List<Tuple<string, string>>();
List<Users> users = db.Users.ToList();
for (int i = 0; i < doctors.Count; i++) {
// Get displayName from users table
string displayName = users.Find(user => user.uuid == doctors[i].user).displayName;
Tuple<string, string> doctor = new Tuple<string, string>(doctors[i].user, displayName);
doctorsList.Add(doctor);
}
ViewBag.doctorsList = new SelectList(doctorsList, "Item1", "Item2");
return View();
}
// POST: Appointments/Create
[HttpPost]
public ActionResult Create(FormCollection collection) {
try {
// TODO: Add insert logic here
return RedirectToAction("Index");
}
catch {
return View();
}
}
// GET: Appointments/Edit/5
public ActionResult Edit(int id) {
return View();
}
// POST: Appointments/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection) {
try {
// TODO: Add update logic here
return RedirectToAction("Index");
}
catch {
return View();
}
}
// GET: Appointments/Delete/5
public ActionResult Delete(int id) {
return View();
}
// POST: Appointments/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection) {
try {
// TODO: Add delete logic here
return RedirectToAction("Index");
}
catch {
return View();
}
}
}
}

View File

@ -255,8 +255,7 @@ namespace FIT5032_Assignment.Controllers {
});
db.SaveChanges();
} else {
db.Doctors.Add(new Doctors
{
db.Doctors.Add(new Doctors {
user = userUuid,
bio = "",
});
@ -334,7 +333,7 @@ namespace FIT5032_Assignment.Controllers {
}
// Check if the email have a patient profile
var db = new Database1Entities();
var dbEntity = new Database1Entities();
// Find the account associated with the email
var app_id = "ZHM5whW5xsZEczTn2loffzjN";
var url = $"https://api.passage.id/v1/apps/{app_id}/users?identifier={model.patientEmail}";
@ -344,13 +343,13 @@ namespace FIT5032_Assignment.Controllers {
return View(model);
}
var patientId = JsonConvert.DeserializeObject<PassageUserFindReply>(res).Users[0].Id;
var patientCredential = db.Credentials.Where(c => (c.uniqueIdCode == patientId) && (c.provider == 0));
var patientCredential = dbEntity.Credentials.Where(c => (c.uniqueIdCode == patientId) && (c.provider == 0));
if (patientCredential.Count() == 0) {
ModelState.AddModelError("patientEmail", "No patient found");
return View(model);
}
var patientUuid = patientCredential.First().user;
var patient = db.Users.Where(u => u.uuid == patientUuid);
var patient = dbEntity.Users.Where(u => u.uuid == patientUuid);
if (patient.Count() == 0 || patient.First().role != 1) {
ModelState.AddModelError("patientEmail", "No patient found");
return View(model);
@ -383,6 +382,7 @@ namespace FIT5032_Assignment.Controllers {
file = fileName,
status = 0,
};
db.SaveChanges();
// Send attached email with mailgun
var doctorName = user.displayName;

View File

@ -184,6 +184,7 @@
<Compile Include="App_Start\BundleConfig.cs" />
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="Controllers\AppointmentsController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
@ -315,8 +316,11 @@
<Content Include="Views\Home\CompleteProfile.cshtml" />
<Content Include="Views\Home\View.cshtml" />
<Content Include="Views\Home\ImageUpload.cshtml" />
<Content Include="Views\Appointments\Index.cshtml" />
<Content Include="Views\Appointments\Create.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Views\Default\" />
<Folder Include="Views\Test\" />
</ItemGroup>
<ItemGroup>

View File

@ -9,7 +9,7 @@
<IISExpressUseClassicPipelineMode />
<UseGlobalApplicationHostFile />
<LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig>
<Controller_SelectedScaffolderID>MvcControllerWithContextScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderID>MvcControllerWithActionsScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
<WebStackScaffolding_ControllerDialogWidth>600</WebStackScaffolding_ControllerDialogWidth>
<WebStackScaffolding_LayoutPageFile>~/Views/Shared/_Layout.cshtml</WebStackScaffolding_LayoutPageFile>
@ -22,6 +22,8 @@
<View_SelectedScaffolderID>MvcViewScaffolder</View_SelectedScaffolderID>
<View_SelectedScaffolderCategoryPath>root/Common/MVC/View</View_SelectedScaffolderCategoryPath>
<WebStackScaffolding_ViewDialogWidth>600</WebStackScaffolding_ViewDialogWidth>
<_SelectedScaffolderID>MvcControllerEmptyScaffolder</_SelectedScaffolderID>
<_SelectedScaffolderCategoryPath>root/Common</_SelectedScaffolderCategoryPath>
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>

View File

@ -0,0 +1,40 @@
@model FIT5032_Assignment.Models.Appointments
@{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Create</h2>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Appointments</h4>
<hr />
<!-- Dropdown menu for select a doctor -->
<div class="form-group">
@Html.LabelFor(model => model.responsibleBy, "Select a doctor", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("user.displayName", @ViewBag.doctorsList as SelectList, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.responsibleBy, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

View File

@ -0,0 +1,11 @@

@{
ViewBag.Title = "Appointments";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Appointments</h2>
<ul>
<li><a href="./Create">Make a new appointment</a></li>
</ul>

View File

@ -1,31 +1,31 @@
@{
ViewBag.Title = "Home Page";
// Check login status
bool loginStatus = false;
ViewBag.Title = "Home Page";
// Check login status
bool loginStatus = false;
// cookie
// cookie
if (Request.Cookies["psg_auth_token"] == null)
{
loginStatus = false;
}
else
{
loginStatus = true;
}
if (Request.Cookies["psg_auth_token"] == null) {
loginStatus = false;
} else {
loginStatus = true;
}
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/jqueryval")
}
@if (loginStatus)
{
@if (loginStatus) {
<img src="@ViewBag.avatar" alt="Avatar" style="width:200px" />
<h1>Welcome back, @ViewBag.displayname</h1>
<p><b>Email address</b> <span id="emailfield">john.appleseed@mac.com</span></p>
<p><b>Role</b> @ViewBag.role</p>
<hr />
<h2>Features</h2>
<p><a href="/Appointments/Index">Appointments</a></p>
<hr />
<p><button id="logoutbutton">Log out</button></p>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>