Exercise Files
This commit is contained in:
6
Ch07/07_02_End/Website/Features/Home/About.cshtml
Normal file
6
Ch07/07_02_End/Website/Features/Home/About.cshtml
Normal file
@ -0,0 +1,6 @@
|
||||
@{
|
||||
ViewBag.Title = "About";
|
||||
}
|
||||
<h3>@ViewBag.Message</h3>
|
||||
|
||||
<p>Use this area to provide additional information.</p>
|
||||
16
Ch07/07_02_End/Website/Features/Home/Contact.cshtml
Normal file
16
Ch07/07_02_End/Website/Features/Home/Contact.cshtml
Normal file
@ -0,0 +1,16 @@
|
||||
@{
|
||||
ViewBag.Title = "Contact";
|
||||
}
|
||||
<h3>@ViewBag.Message</h3>
|
||||
|
||||
<address>
|
||||
One Microsoft Way<br />
|
||||
Redmond, WA 98052-6399<br />
|
||||
<abbr title="Phone">P:</abbr>
|
||||
425.555.0100
|
||||
</address>
|
||||
|
||||
<address>
|
||||
<strong>Support:</strong> <a href="mailto:Support@example.com">Support@example.com</a><br />
|
||||
<strong>Marketing:</strong> <a href="mailto:Marketing@example.com">Marketing@example.com</a>
|
||||
</address>
|
||||
57
Ch07/07_02_End/Website/Features/Home/HomeController.cs
Normal file
57
Ch07/07_02_End/Website/Features/Home/HomeController.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using HPlusSports.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace HPlusSports.Controllers
|
||||
{
|
||||
[RoutePrefix("home/{name}")]
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly HPlusSportsDbContext _context;
|
||||
|
||||
public HomeController()
|
||||
: this(new HPlusSportsDbContext())
|
||||
{
|
||||
}
|
||||
|
||||
public HomeController(HPlusSportsDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
var categories =
|
||||
(
|
||||
from category in _context.Categories
|
||||
let count = _context.Products.Count(x => x.CategoryId == category.Id)
|
||||
select new { category, count }
|
||||
).ToDictionary(x => x.category, x => x.count);
|
||||
|
||||
return View(categories);
|
||||
}
|
||||
|
||||
[Route("about")]
|
||||
public ActionResult About(string name)
|
||||
{
|
||||
ViewBag.Message = "Your application description page, " + name;
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Broken(string error)
|
||||
{
|
||||
throw new Exception(error);
|
||||
}
|
||||
|
||||
public ActionResult Contact()
|
||||
{
|
||||
ViewBag.Message = "Your contact page.";
|
||||
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Ch07/07_02_End/Website/Features/Home/Index.cshtml
Normal file
19
Ch07/07_02_End/Website/Features/Home/Index.cshtml
Normal file
@ -0,0 +1,19 @@
|
||||
@model IDictionary<HPlusSports.Models.Category, int>
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Categories";
|
||||
}
|
||||
|
||||
<div class="row">
|
||||
|
||||
@foreach (var category in Model.Keys)
|
||||
{
|
||||
<div class="category col-md-4 text-center">
|
||||
<a href="@Url.Action("Category", "Products", new { id = category.Key })">
|
||||
<img class="img-thumbnail" src="@Url.Action("Category", "Images", new { id = category.Key })" />
|
||||
<h3>@category.Name</h3>
|
||||
</a>
|
||||
</div>
|
||||
}
|
||||
|
||||
</div>
|
||||
Reference in New Issue
Block a user