From 72b29d9c78c06c96e051d505aa428d73035b3524 Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Fri, 15 Sep 2023 08:31:37 +1000 Subject: [PATCH] Create Account View --- FIT5032-Assignment/App_Start/RouteConfig.cs | 9 +- .../Controllers/HomeController.cs | 7 + .../Controllers/UsersController.cs | 136 ------------------ FIT5032-Assignment/FIT5032-Assignment.csproj | 8 +- .../FIT5032-Assignment.csproj.user | 3 + .../Models/CreateAccountForm.cs | 23 +++ .../Edit.cshtml => Home/CreateAccount.cshtml} | 26 ++-- FIT5032-Assignment/Views/Users/Create.cshtml | 65 --------- FIT5032-Assignment/Views/Users/Delete.cshtml | 65 --------- FIT5032-Assignment/Views/Users/Details.cshtml | 59 -------- FIT5032-Assignment/Views/Users/Index.cshtml | 58 -------- 11 files changed, 55 insertions(+), 404 deletions(-) delete mode 100644 FIT5032-Assignment/Controllers/UsersController.cs create mode 100644 FIT5032-Assignment/Models/CreateAccountForm.cs rename FIT5032-Assignment/Views/{Users/Edit.cshtml => Home/CreateAccount.cshtml} (54%) delete mode 100644 FIT5032-Assignment/Views/Users/Create.cshtml delete mode 100644 FIT5032-Assignment/Views/Users/Delete.cshtml delete mode 100644 FIT5032-Assignment/Views/Users/Details.cshtml delete mode 100644 FIT5032-Assignment/Views/Users/Index.cshtml diff --git a/FIT5032-Assignment/App_Start/RouteConfig.cs b/FIT5032-Assignment/App_Start/RouteConfig.cs index 7195dec..c710d87 100644 --- a/FIT5032-Assignment/App_Start/RouteConfig.cs +++ b/FIT5032-Assignment/App_Start/RouteConfig.cs @@ -13,11 +13,18 @@ namespace FIT5032_Assignment { 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 } + ); + + /*routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } - ); + );*/ } } } diff --git a/FIT5032-Assignment/Controllers/HomeController.cs b/FIT5032-Assignment/Controllers/HomeController.cs index 72690a8..018c0e4 100644 --- a/FIT5032-Assignment/Controllers/HomeController.cs +++ b/FIT5032-Assignment/Controllers/HomeController.cs @@ -13,6 +13,13 @@ namespace FIT5032_Assignment.Controllers return View(); } + public ActionResult CreateAccount() + { + return View(); + } } + + // POST /CreateAccount + } \ No newline at end of file diff --git a/FIT5032-Assignment/Controllers/UsersController.cs b/FIT5032-Assignment/Controllers/UsersController.cs deleted file mode 100644 index 8ee0959..0000000 --- a/FIT5032-Assignment/Controllers/UsersController.cs +++ /dev/null @@ -1,136 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Entity; -using System.Linq; -using System.Net; -using System.Web; -using System.Web.Mvc; -using FIT5032_Assignment.Models; - -namespace FIT5032_Assignment.Controllers -{ - public class UsersController : Controller - { - private Database1Entities db = new Database1Entities(); - - // GET: Users - public ActionResult Index() - { - var users = db.Users.Include(u => u.Doctors).Include(u => u.Patients); - return View(users.ToList()); - } - - // GET: Users/Details/5 - public ActionResult Details(string id) - { - if (id == null) - { - return new HttpStatusCodeResult(HttpStatusCode.BadRequest); - } - Users users = db.Users.Find(id); - if (users == null) - { - return HttpNotFound(); - } - return View(users); - } - - // GET: Users/Create - public ActionResult Create() - { - ViewBag.uuid = new SelectList(db.Doctors, "user", "bio"); - ViewBag.uuid = new SelectList(db.Patients, "user", "phone"); - return View(); - } - - // POST: Users/Create - // To protect from overposting attacks, enable the specific properties you want to bind to, for - // more details see https://go.microsoft.com/fwlink/?LinkId=317598. - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Create([Bind(Include = "uuid,displayName,avatar,role")] Users users) - { - if (ModelState.IsValid) - { - db.Users.Add(users); - db.SaveChanges(); - return RedirectToAction("Index"); - } - - ViewBag.uuid = new SelectList(db.Doctors, "user", "bio", users.uuid); - ViewBag.uuid = new SelectList(db.Patients, "user", "phone", users.uuid); - return View(users); - } - - // GET: Users/Edit/5 - public ActionResult Edit(string id) - { - if (id == null) - { - return new HttpStatusCodeResult(HttpStatusCode.BadRequest); - } - Users users = db.Users.Find(id); - if (users == null) - { - return HttpNotFound(); - } - ViewBag.uuid = new SelectList(db.Doctors, "user", "bio", users.uuid); - ViewBag.uuid = new SelectList(db.Patients, "user", "phone", users.uuid); - return View(users); - } - - // POST: Users/Edit/5 - // To protect from overposting attacks, enable the specific properties you want to bind to, for - // more details see https://go.microsoft.com/fwlink/?LinkId=317598. - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Edit([Bind(Include = "uuid,displayName,avatar,role")] Users users) - { - if (ModelState.IsValid) - { - db.Entry(users).State = EntityState.Modified; - db.SaveChanges(); - return RedirectToAction("Index"); - } - ViewBag.uuid = new SelectList(db.Doctors, "user", "bio", users.uuid); - ViewBag.uuid = new SelectList(db.Patients, "user", "phone", users.uuid); - return View(users); - } - - // GET: Users/Delete/5 - public ActionResult Delete(string id) - { - if (id == null) - { - return new HttpStatusCodeResult(HttpStatusCode.BadRequest); - } - Users users = db.Users.Find(id); - if (users == null) - { - return HttpNotFound(); - } - return View(users); - } - - // POST: Users/Delete/5 - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public ActionResult DeleteConfirmed(string id) - { - Users users = db.Users.Find(id); - db.Users.Remove(users); - db.SaveChanges(); - return RedirectToAction("Index"); - } - - protected override void Dispose(bool disposing) - { - if (disposing) - { - db.Dispose(); - } - base.Dispose(disposing); - } - } -} diff --git a/FIT5032-Assignment/FIT5032-Assignment.csproj b/FIT5032-Assignment/FIT5032-Assignment.csproj index 53031db..82563bc 100644 --- a/FIT5032-Assignment/FIT5032-Assignment.csproj +++ b/FIT5032-Assignment/FIT5032-Assignment.csproj @@ -130,13 +130,13 @@ - Global.asax FIT5032-Assignment.tt + FIT5032-Assignment.tt @@ -251,11 +251,7 @@ - - - - - + diff --git a/FIT5032-Assignment/FIT5032-Assignment.csproj.user b/FIT5032-Assignment/FIT5032-Assignment.csproj.user index f319be8..8ab049b 100644 --- a/FIT5032-Assignment/FIT5032-Assignment.csproj.user +++ b/FIT5032-Assignment/FIT5032-Assignment.csproj.user @@ -19,6 +19,9 @@ FIT5032_Assignment.Models.Database1Entities True False + MvcViewScaffolder + root/Common/MVC/View + 600 diff --git a/FIT5032-Assignment/Models/CreateAccountForm.cs b/FIT5032-Assignment/Models/CreateAccountForm.cs new file mode 100644 index 0000000..596885b --- /dev/null +++ b/FIT5032-Assignment/Models/CreateAccountForm.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.ComponentModel.DataAnnotations; + +namespace FIT5032_Assignment.Models +{ + public class CreateAccountForm + { + [Required] + [Display(Name = "Email address")] + public string emailaddress { get; set; } + + [Required] + [Display(Name = "Full name")] + public string fullname { get; set; } + + [Required] + [Display(Name = "Which role do you want to assign?")] + public Int16 role { get; set; } + } +} \ No newline at end of file diff --git a/FIT5032-Assignment/Views/Users/Edit.cshtml b/FIT5032-Assignment/Views/Home/CreateAccount.cshtml similarity index 54% rename from FIT5032-Assignment/Views/Users/Edit.cshtml rename to FIT5032-Assignment/Views/Home/CreateAccount.cshtml index f526434..4bac6ee 100644 --- a/FIT5032-Assignment/Views/Users/Edit.cshtml +++ b/FIT5032-Assignment/Views/Home/CreateAccount.cshtml @@ -1,36 +1,34 @@ -@model FIT5032_Assignment.Models.Users +@model FIT5032_Assignment.Models.CreateAccountForm @{ - ViewBag.Title = "Edit"; + ViewBag.Title = "CreateAccount"; Layout = "~/Views/Shared/_Layout.cshtml"; } -

Edit

+

CreateAccount

-@using (Html.BeginForm()) +@using (Html.BeginForm()) { @Html.AntiForgeryToken()
-

Users

+

CreateAccountForm


@Html.ValidationSummary(true, "", new { @class = "text-danger" }) - @Html.HiddenFor(model => model.uuid) -
- @Html.LabelFor(model => model.displayName, htmlAttributes: new { @class = "control-label col-md-2" }) + @Html.LabelFor(model => model.emailaddress, htmlAttributes: new { @class = "control-label col-md-2" })
- @Html.EditorFor(model => model.displayName, new { htmlAttributes = new { @class = "form-control" } }) - @Html.ValidationMessageFor(model => model.displayName, "", new { @class = "text-danger" }) + @Html.EditorFor(model => model.emailaddress, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.emailaddress, "", new { @class = "text-danger" })
- @Html.LabelFor(model => model.avatar, htmlAttributes: new { @class = "control-label col-md-2" }) + @Html.LabelFor(model => model.fullname, htmlAttributes: new { @class = "control-label col-md-2" })
- @Html.EditorFor(model => model.avatar, new { htmlAttributes = new { @class = "form-control" } }) - @Html.ValidationMessageFor(model => model.avatar, "", new { @class = "text-danger" }) + @Html.EditorFor(model => model.fullname, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.fullname, "", new { @class = "text-danger" })
@@ -44,7 +42,7 @@
- +
diff --git a/FIT5032-Assignment/Views/Users/Create.cshtml b/FIT5032-Assignment/Views/Users/Create.cshtml deleted file mode 100644 index 857231e..0000000 --- a/FIT5032-Assignment/Views/Users/Create.cshtml +++ /dev/null @@ -1,65 +0,0 @@ -@model FIT5032_Assignment.Models.Users - -@{ - ViewBag.Title = "Create"; - Layout = "~/Views/Shared/_Layout.cshtml"; -} - -

Create

- - -@using (Html.BeginForm()) -{ - @Html.AntiForgeryToken() - -
-

Users

-
- @Html.ValidationSummary(true, "", new { @class = "text-danger" }) -
- @Html.LabelFor(model => model.uuid, htmlAttributes: new { @class = "control-label col-md-2" }) -
- @Html.EditorFor(model => model.uuid, new { htmlAttributes = new { @class = "form-control" } }) - @Html.ValidationMessageFor(model => model.uuid, "", new { @class = "text-danger" }) -
-
- -
- @Html.LabelFor(model => model.displayName, htmlAttributes: new { @class = "control-label col-md-2" }) -
- @Html.EditorFor(model => model.displayName, new { htmlAttributes = new { @class = "form-control" } }) - @Html.ValidationMessageFor(model => model.displayName, "", new { @class = "text-danger" }) -
-
- -
- @Html.LabelFor(model => model.avatar, htmlAttributes: new { @class = "control-label col-md-2" }) -
- @Html.EditorFor(model => model.avatar, new { htmlAttributes = new { @class = "form-control" } }) - @Html.ValidationMessageFor(model => model.avatar, "", new { @class = "text-danger" }) -
-
- -
- @Html.LabelFor(model => model.role, htmlAttributes: new { @class = "control-label col-md-2" }) -
- @Html.EditorFor(model => model.role, new { htmlAttributes = new { @class = "form-control" } }) - @Html.ValidationMessageFor(model => model.role, "", new { @class = "text-danger" }) -
-
- -
-
- -
-
-
-} - -
- @Html.ActionLink("Back to List", "Index") -
- -@section Scripts { - @Scripts.Render("~/bundles/jqueryval") -} diff --git a/FIT5032-Assignment/Views/Users/Delete.cshtml b/FIT5032-Assignment/Views/Users/Delete.cshtml deleted file mode 100644 index 8c1ac70..0000000 --- a/FIT5032-Assignment/Views/Users/Delete.cshtml +++ /dev/null @@ -1,65 +0,0 @@ -@model FIT5032_Assignment.Models.Users - -@{ - ViewBag.Title = "Delete"; - Layout = "~/Views/Shared/_Layout.cshtml"; -} - -

Delete

- -

Are you sure you want to delete this?

-
-

Users

-
-
-
- @Html.DisplayNameFor(model => model.displayName) -
- -
- @Html.DisplayFor(model => model.displayName) -
- -
- @Html.DisplayNameFor(model => model.avatar) -
- -
- @Html.DisplayFor(model => model.avatar) -
- -
- @Html.DisplayNameFor(model => model.role) -
- -
- @Html.DisplayFor(model => model.role) -
- -
- @Html.DisplayNameFor(model => model.Doctors.bio) -
- -
- @Html.DisplayFor(model => model.Doctors.bio) -
- -
- @Html.DisplayNameFor(model => model.Patients.phone) -
- -
- @Html.DisplayFor(model => model.Patients.phone) -
- -
- - @using (Html.BeginForm()) { - @Html.AntiForgeryToken() - -
- | - @Html.ActionLink("Back to List", "Index") -
- } -
diff --git a/FIT5032-Assignment/Views/Users/Details.cshtml b/FIT5032-Assignment/Views/Users/Details.cshtml deleted file mode 100644 index d3c8e88..0000000 --- a/FIT5032-Assignment/Views/Users/Details.cshtml +++ /dev/null @@ -1,59 +0,0 @@ -@model FIT5032_Assignment.Models.Users - -@{ - ViewBag.Title = "Details"; - Layout = "~/Views/Shared/_Layout.cshtml"; -} - -

Details

- -
-

Users

-
-
-
- @Html.DisplayNameFor(model => model.displayName) -
- -
- @Html.DisplayFor(model => model.displayName) -
- -
- @Html.DisplayNameFor(model => model.avatar) -
- -
- @Html.DisplayFor(model => model.avatar) -
- -
- @Html.DisplayNameFor(model => model.role) -
- -
- @Html.DisplayFor(model => model.role) -
- -
- @Html.DisplayNameFor(model => model.Doctors.bio) -
- -
- @Html.DisplayFor(model => model.Doctors.bio) -
- -
- @Html.DisplayNameFor(model => model.Patients.phone) -
- -
- @Html.DisplayFor(model => model.Patients.phone) -
- -
-
-

- @Html.ActionLink("Edit", "Edit", new { id = Model.uuid }) | - @Html.ActionLink("Back to List", "Index") -

diff --git a/FIT5032-Assignment/Views/Users/Index.cshtml b/FIT5032-Assignment/Views/Users/Index.cshtml deleted file mode 100644 index b2a04a5..0000000 --- a/FIT5032-Assignment/Views/Users/Index.cshtml +++ /dev/null @@ -1,58 +0,0 @@ -@model IEnumerable - -@{ - ViewBag.Title = "Index"; - Layout = "~/Views/Shared/_Layout.cshtml"; -} - -

Index

- -

- @Html.ActionLink("Create New", "Create") -

- - - - - - - - - - -@foreach (var item in Model) { - - - - - - - - -} - -
- @Html.DisplayNameFor(model => model.displayName) - - @Html.DisplayNameFor(model => model.avatar) - - @Html.DisplayNameFor(model => model.role) - - @Html.DisplayNameFor(model => model.Doctors.bio) - - @Html.DisplayNameFor(model => model.Patients.phone) -
- @Html.DisplayFor(modelItem => item.displayName) - - @Html.DisplayFor(modelItem => item.avatar) - - @Html.DisplayFor(modelItem => item.role) - - @Html.DisplayFor(modelItem => item.Doctors.bio) - - @Html.DisplayFor(modelItem => item.Patients.phone) - - @Html.ActionLink("Edit", "Edit", new { id=item.uuid }) | - @Html.ActionLink("Details", "Details", new { id=item.uuid }) | - @Html.ActionLink("Delete", "Delete", new { id=item.uuid }) -