Image upload page

This commit is contained in:
Astrian Zheng 2023-10-11 21:28:53 +11:00
parent 35c458b236
commit 68966ed7d7
5 changed files with 125 additions and 30 deletions

View File

@ -249,12 +249,60 @@ namespace FIT5032_Assignment.Controllers {
} }
public ActionResult ImageUpload() { public ActionResult ImageUpload() {
var user = loginVerify(Request.Cookies["psg_auth_token"].Value); try {
if (user != null) { if (Request.Cookies["psg_auth_token"] == null) {
// Redirect to home page // Redirect to home page
return RedirectToAction("Index");
}
var user = loginVerify(Request.Cookies["psg_auth_token"].Value);
if (user == null) {
// Redirect to home page
return RedirectToAction("Index");
} else {
// Detect if user is doctor or patient
var db = new Database1Entities();
var credential = db.Credentials.Where(res => (res.uniqueIdCode == user) && (res.provider == 0));
if (credential.Count() == 0) {
// Redirect to create account
return RedirectToAction("Index");
} else {
// Redirect to image upload
return View();
}
}
} catch (Exception e ) {
Trace.WriteLine(e);
return RedirectToAction("Index");
}
}
[HttpPost]
public ActionResult ImageUpload(Models.ImageUploadForm model) {
try {
if (Request.Cookies["psg_auth_token"] == null) {
// Redirect to home page
return new HttpStatusCodeResult(HttpStatusCode.Forbidden);
}
var user = loginVerify(Request.Cookies["psg_auth_token"].Value);
if (user == null) {
// Redirect to home page
return new HttpStatusCodeResult(HttpStatusCode.Forbidden);
} else {
// Detect if user is doctor or patient
var db = new Database1Entities();
var credential = db.Credentials.Where(res => (res.uniqueIdCode == user) && (res.provider == 0));
if (credential.Count() == 0) {
// return error 403
return new HttpStatusCodeResult(HttpStatusCode.Forbidden);
}
var dbUser = db.Users.Where(res => res.uuid == credential.First().user);
// print dbUser
Trace.WriteLine(dbUser.First());
return View();
}
} catch (Exception e) {
Trace.WriteLine(e);
return RedirectToAction("Index"); return RedirectToAction("Index");
} else {
return View();
} }
} }
} }

View File

@ -188,6 +188,7 @@
<Compile Include="Models\Appointments.cs"> <Compile Include="Models\Appointments.cs">
<DependentUpon>FIT5032-Assignment.tt</DependentUpon> <DependentUpon>FIT5032-Assignment.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="Models\ImageUploadForm.cs" />
<Compile Include="Models\CompleteProfileForm.cs" /> <Compile Include="Models\CompleteProfileForm.cs" />
<Compile Include="Models\Credentials.cs"> <Compile Include="Models\Credentials.cs">
<DependentUpon>FIT5032-Assignment.tt</DependentUpon> <DependentUpon>FIT5032-Assignment.tt</DependentUpon>

View File

@ -0,0 +1,14 @@
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace FIT5032_Assignment.Models {
public class ImageUploadForm {
[Required]
[Display(Name = "Assign to patient (email)")]
public string patientEmail { get; set; }
[Required]
[Display(Name = "Image file")]
public HttpPostedFileBase imageFile { get; set; }
}
}

View File

@ -7,24 +7,22 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace FIT5032_Assignment.Models namespace FIT5032_Assignment.Models {
{ using System;
using System; using System.Collections.Generic;
using System.Collections.Generic;
public partial class Images public partial class Images {
{ public string uuid { get; set; }
public string uuid { get; set; } public string patient { get; set; }
public string patient { get; set; } public string responsibleBy { get; set; }
public string responsibleBy { get; set; } public Nullable<System.DateTime> createdAt { get; set; }
public Nullable<System.DateTime> createdAt { get; set; } public string appointment { get; set; }
public string appointment { get; set; } public Nullable<int> status { get; set; }
public Nullable<int> status { get; set; } public string file { get; set; }
public string file { get; set; }
public virtual Appointments Appointments { get; set; } public virtual Appointments Appointments { get; set; }
public virtual Doctors Doctors { get; set; } public virtual Doctors Doctors { get; set; }
public virtual Patients Patients { get; set; } public virtual Patients Patients { get; set; }
public virtual ShareURLs ShareURLs { get; set; } public virtual ShareURLs ShareURLs { get; set; }
} }
} }

View File

@ -1,8 +1,42 @@
@{ @model FIT5032_Assignment.Models.ImageUploadForm
Layout = "~/Views/Shared/_Layout.cshtml"; @{
Layout = "~/Views/Shared/_Layout.cshtml";
} }
<main aria-labelledby="title"> @using (Html.BeginForm())
image upload {
</main> @Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Upload Image</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.patientEmail, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.patientEmail, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.patientEmail, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.imageFile, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.imageFile, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.imageFile, "", 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>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}