From d240d7d5693d23ee50ae4bc95e51c7003e298f64 Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Wed, 8 Sep 2021 22:33:17 +1000 Subject: [PATCH] 8.1.3.2 Generating Category Lists; Listing 8-7 Implementing the Menu Method in the NavController.cs File --- .../Controllers/NavController.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/SportsStore/SportsStore.WebUI/Controllers/NavController.cs b/SportsStore/SportsStore.WebUI/Controllers/NavController.cs index 99019bc..5c046bd 100644 --- a/SportsStore/SportsStore.WebUI/Controllers/NavController.cs +++ b/SportsStore/SportsStore.WebUI/Controllers/NavController.cs @@ -3,14 +3,27 @@ using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; +using SportsStore.Domain.Abstract; namespace SportsStore.WebUI.Controllers { public class NavController : Controller { - public string Menu() + private IProductRepository repository; + + public NavController(IProductRepository repo) { - return "Hello from NavController"; + repository = repo; + } + + public PartialViewResult Menu() + { + IEnumerable categories = repository.Products + .Select(x => x.Category) + .Distinct() + .OrderBy(x => x); + + return PartialView(categories); } } } \ No newline at end of file