Exercise Files
This commit is contained in:
95
Ch03/03_Challenge/Website/Views/Inventory/Create.cshtml
Normal file
95
Ch03/03_Challenge/Website/Views/Inventory/Create.cshtml
Normal file
@ -0,0 +1,95 @@
|
||||
@model HPlusSports.Models.Product
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Add New Product";
|
||||
}
|
||||
|
||||
@using (Html.BeginForm())
|
||||
{
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
|
||||
@*
|
||||
Add these hidden fields so validation doesn't fail,
|
||||
even though they are going to get overridden on the
|
||||
server anyway.
|
||||
*@
|
||||
@Html.Hidden(nameof(Model.LastUpdated), DateTime.Now.ToString())
|
||||
@Html.Hidden(nameof(Model.LastUpdatedUserId), User.Identity.Name)
|
||||
|
||||
|
||||
<div class="form-horizontal">
|
||||
<h4>Product</h4>
|
||||
<hr />
|
||||
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.CategoryId, "CategoryId", htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.DropDownListFor(model => model.CategoryId, null, htmlAttributes: new { @class = "form-control" })
|
||||
@Html.ValidationMessageFor(model => model.CategoryId, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.SKU, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.SKU, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.SKU, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.Summary, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.Summary, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.Summary, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.MSRP, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.MSRP, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.MSRP, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.Price, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.Price, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.Price, "", 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")
|
||||
}
|
||||
93
Ch03/03_Challenge/Website/Views/Inventory/Index.cshtml
Normal file
93
Ch03/03_Challenge/Website/Views/Inventory/Index.cshtml
Normal file
@ -0,0 +1,93 @@
|
||||
@model IEnumerable<HPlusSports.Models.Product>
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Inventory";
|
||||
}
|
||||
|
||||
@if (TempData["SuccessMessage"] != null)
|
||||
{
|
||||
<div class="alert alert-error alert-dismissible" role="alert">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
@TempData["SuccessMessage"]
|
||||
</div>
|
||||
}
|
||||
else if (TempData["ErrorMessage"] != null)
|
||||
{
|
||||
<div class="alert alert-error alert-dismissible" role="alert">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
@TempData["ErrorMessage"]
|
||||
</div>
|
||||
}
|
||||
|
||||
<h2>
|
||||
@ViewBag.Title
|
||||
<a class="btn btn-primary btn-sm pull-right" href="@Url.Action("Create")">Add Product</a>
|
||||
</h2>
|
||||
|
||||
<table class="table tablesorter">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Category
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.SKU)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Name)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Price)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Description)
|
||||
</th>
|
||||
<th>
|
||||
Last Update
|
||||
</th>
|
||||
<th disabled></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Category.Name)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.SKU)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Name)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Price)
|
||||
<span class="clearfix text-muted">
|
||||
@Html.DisplayFor(modelItem => item.MSRP)
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Description)
|
||||
</td>
|
||||
<td>
|
||||
<span class="text-muted">
|
||||
<span title="@item.LastUpdated.ToString()">
|
||||
@item.LastUpdated.ToShortDateString()
|
||||
</span>
|
||||
by
|
||||
@item.LastUpdatedUserId
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<a href="@Url.Action("Update", new { id = item.Id })">
|
||||
<i class="glyphicon glyphicon-pencil text-info"></i>
|
||||
</a>
|
||||
<a href="@Url.Action("Delete", new { id = item.Id })">
|
||||
<i class="glyphicon glyphicon-remove text-danger"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
104
Ch03/03_Challenge/Website/Views/Inventory/Update.cshtml
Normal file
104
Ch03/03_Challenge/Website/Views/Inventory/Update.cshtml
Normal file
@ -0,0 +1,104 @@
|
||||
@model HPlusSports.Models.Product
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Update Product";
|
||||
}
|
||||
|
||||
<h2>@ViewBag.Title</h2>
|
||||
|
||||
|
||||
@using (Html.BeginForm())
|
||||
{
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
<div class="form-horizontal">
|
||||
<h4>Product</h4>
|
||||
<hr />
|
||||
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
|
||||
@Html.HiddenFor(model => model.Id)
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.CategoryId, "CategoryId", htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.DropDownListFor(model => model.CategoryId, null, htmlAttributes: new { @class = "form-control" })
|
||||
@Html.ValidationMessageFor(model => model.CategoryId, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.SKU, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.SKU, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.SKU, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.Summary, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.Summary, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.Summary, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.MSRP, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.MSRP, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.MSRP, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.Price, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.Price, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.Price, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.LastUpdated, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.DisplayFor(model => model.LastUpdated, new { htmlAttributes = new { @class = "form-control" } })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.LastUpdatedUserId, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.DisplayFor(model => model.LastUpdatedUserId, new { htmlAttributes = new { @class = "form-control" } })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<input type="submit" value="Save" class="btn btn-default" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div>
|
||||
@Html.ActionLink("Back to List", "Index")
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
@Scripts.Render("~/bundles/jqueryval")
|
||||
}
|
||||
Reference in New Issue
Block a user