From fc49f33575745842c4050ea3aa559a0da252d52f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Mon, 4 May 2020 22:40:48 +0200 Subject: [PATCH] Viewing and creating new people implemented --- MVCUI/Content/bootstrap.css | 4 +- MVCUI/Controllers/PeopleController.cs | 51 +++++++++++++++++++++ MVCUI/MVCUI.csproj | 3 ++ MVCUI/Views/People/Create.cshtml | 64 +++++++++++++++++++++++++++ MVCUI/Views/People/Index.cshtml | 45 +++++++++++++++++++ MVCUI/Views/Shared/_Layout.cshtml | 13 +++--- TrackerLibrary/Models/PersonModel.cs | 13 ++++++ TrackerLibrary/TrackerLibrary.csproj | 1 + 8 files changed, 187 insertions(+), 7 deletions(-) create mode 100644 MVCUI/Controllers/PeopleController.cs create mode 100644 MVCUI/Views/People/Create.cshtml create mode 100644 MVCUI/Views/People/Index.cshtml diff --git a/MVCUI/Content/bootstrap.css b/MVCUI/Content/bootstrap.css index e9cf28e..7dfbda6 100644 --- a/MVCUI/Content/bootstrap.css +++ b/MVCUI/Content/bootstrap.css @@ -10801,7 +10801,7 @@ a.text-dark:hover, a.text-dark:focus { } .table { - font-size: 0.875rem; + font-size: 16px; } .table .thead-dark th { @@ -10919,7 +10919,7 @@ label, .radio label, .checkbox label, .help-block { - font-size: 0.875rem; + font-size: 18px; } .nav-tabs .nav-link, diff --git a/MVCUI/Controllers/PeopleController.cs b/MVCUI/Controllers/PeopleController.cs new file mode 100644 index 0000000..b7bf918 --- /dev/null +++ b/MVCUI/Controllers/PeopleController.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using TrackerLibrary; +using TrackerLibrary.Models; + +namespace MVCUI.Controllers +{ + public class PeopleController : Controller + { + // GET: People + public ActionResult Index() + { + List availablePeople = GlobalConfig.Connection.GetPerson_All(); + return View(availablePeople); + } + + + // GET: People/Create + public ActionResult Create() + { + return View(); + } + + // POST: People/Create + [HttpPost] + public ActionResult Create(PersonModel p) + { + try + { + if (ModelState.IsValid) + { + GlobalConfig.Connection.CreatePerson(p); + return RedirectToAction("Index"); + } + else + { + return View(); + + } + } + catch + { + return View(); + } + } + + } +} diff --git a/MVCUI/MVCUI.csproj b/MVCUI/MVCUI.csproj index 19aa643..8e86820 100644 --- a/MVCUI/MVCUI.csproj +++ b/MVCUI/MVCUI.csproj @@ -123,6 +123,7 @@ + Global.asax @@ -263,6 +264,8 @@ + + diff --git a/MVCUI/Views/People/Create.cshtml b/MVCUI/Views/People/Create.cshtml new file mode 100644 index 0000000..0fa18b3 --- /dev/null +++ b/MVCUI/Views/People/Create.cshtml @@ -0,0 +1,64 @@ +@model TrackerLibrary.Models.PersonModel + +@{ + ViewBag.Title = "Create"; +} + +

Create New Person

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

PersonModel

+
+ @Html.ValidationSummary(true, "", new { @class = "text-danger" }) +
+ @Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.EmailAddress, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.EmailAddress, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.EmailAddress, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.CellPhoneNumber, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.CellPhoneNumber, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.CellPhoneNumber, "", new { @class = "text-danger" }) +
+
+ +
+
+ +
+
+
+} + +
+ @Html.ActionLink("Back to List", "Index") +
+ +@section Scripts { + @Scripts.Render("~/bundles/jqueryval") +} diff --git a/MVCUI/Views/People/Index.cshtml b/MVCUI/Views/People/Index.cshtml new file mode 100644 index 0000000..0428ddf --- /dev/null +++ b/MVCUI/Views/People/Index.cshtml @@ -0,0 +1,45 @@ +@model IEnumerable + +@{ + ViewBag.Title = "Index"; +} + +

View All People

+ +

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

+ + + + + + + + +@foreach (var item in Model) { + + + + + + +} + +
+ @Html.DisplayNameFor(model => model.FirstName) + + @Html.DisplayNameFor(model => model.LastName) + + @Html.DisplayNameFor(model => model.EmailAddress) + + @Html.DisplayNameFor(model => model.CellPhoneNumber) +
+ @Html.DisplayFor(modelItem => item.FirstName) + + @Html.DisplayFor(modelItem => item.LastName) + + @Html.DisplayFor(modelItem => item.EmailAddress) + + @Html.DisplayFor(modelItem => item.CellPhoneNumber) +
diff --git a/MVCUI/Views/Shared/_Layout.cshtml b/MVCUI/Views/Shared/_Layout.cshtml index 69cc21d..aa7a3fe 100644 --- a/MVCUI/Views/Shared/_Layout.cshtml +++ b/MVCUI/Views/Shared/_Layout.cshtml @@ -24,12 +24,15 @@ - @* *@ + @Html.ActionLink("People", "Index", "People", new { area = "" }, new { @class = "nav-link text-light" }) + + @* + *@ diff --git a/TrackerLibrary/Models/PersonModel.cs b/TrackerLibrary/Models/PersonModel.cs index 407ed12..050ec3f 100644 --- a/TrackerLibrary/Models/PersonModel.cs +++ b/TrackerLibrary/Models/PersonModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Text; namespace TrackerLibrary.Models @@ -10,9 +11,21 @@ namespace TrackerLibrary.Models /// The unique identifier for the prize /// public int Id { get; set; } + [Display(Name="Given Name")] + [StringLength(100,MinimumLength =2)] + [Required] public string FirstName { get; set; } + [Display(Name = "Last Name")] + [StringLength(100, MinimumLength = 2)] + [Required] public string LastName { get; set; } + [Display(Name = "Email Address")] + [StringLength(200, MinimumLength = 6)] + [Required] public string EmailAddress { get; set; } + [Display(Name = "Cellphone Number")] + [StringLength(20, MinimumLength = 10)] + [Required] public string CellPhoneNumber { get; set; } public string FullName { diff --git a/TrackerLibrary/TrackerLibrary.csproj b/TrackerLibrary/TrackerLibrary.csproj index 553058a..468a692 100644 --- a/TrackerLibrary/TrackerLibrary.csproj +++ b/TrackerLibrary/TrackerLibrary.csproj @@ -47,6 +47,7 @@ ..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll +