Viewing and creating new people implemented

This commit is contained in:
2020-05-04 22:40:48 +02:00
parent 9957004b80
commit fc49f33575
8 changed files with 187 additions and 7 deletions

View File

@ -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,

View File

@ -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<PersonModel> 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();
}
}
}
}

View File

@ -123,6 +123,7 @@
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\PeopleController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
@ -263,6 +264,8 @@
<Content Include="Scripts\popper.js.map" />
<Content Include="Scripts\popper-utils.min.js.map" />
<Content Include="Scripts\popper-utils.js.map" />
<Content Include="Views\People\Index.cshtml" />
<Content Include="Views\People\Create.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />

View File

@ -0,0 +1,64 @@
@model TrackerLibrary.Models.PersonModel
@{
ViewBag.Title = "Create";
}
<h2>Create New Person</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>PersonModel</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.EmailAddress, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.EmailAddress, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.EmailAddress, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CellPhoneNumber, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CellPhoneNumber, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CellPhoneNumber, "", 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,45 @@
@model IEnumerable<TrackerLibrary.Models.PersonModel>
@{
ViewBag.Title = "Index";
}
<h2>View All People</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.EmailAddress)
</th>
<th>
@Html.DisplayNameFor(model => model.CellPhoneNumber)
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmailAddress)
</td>
<td>
@Html.DisplayFor(modelItem => item.CellPhoneNumber)
</td>
</tr>
}
</table>

View File

@ -24,12 +24,15 @@
<li class="nav-item">
@Html.ActionLink("Home", "Index", "Home", new { area = "" }, new { @class = "nav-link text-light" })
</li>
@*<li class="nav-item">
@Html.ActionLink("About", "About", "Home", new { area = "" }, new { @class = "nav-link text-light" })
</li>
<li class="nav-item">
@Html.ActionLink("Contact", "Contact", "Home", new { area = "" }, new { @class = "nav-link text-light" })
</li>*@
@Html.ActionLink("People", "Index", "People", new { area = "" }, new { @class = "nav-link text-light" })
</li>
@*<li class="nav-item">
@Html.ActionLink("About", "About", "Home", new { area = "" }, new { @class = "nav-link text-light" })
</li>
<li class="nav-item">
@Html.ActionLink("Contact", "Contact", "Home", new { area = "" }, new { @class = "nav-link text-light" })
</li>*@
</ul>
</div>
</nav>

View File

@ -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
/// </summary>
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
{

View File

@ -47,6 +47,7 @@
<HintPath>..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=5.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">