1: public class NavController : Controller
2: {
3: private IProductRepository repository;
4: public NavController(IProductRepository repo)
5: {
6: repository = repo;
7: }
8: public PartialViewResult Menu(string category=null)
9: {
10: ViewBag.SelectedCategory = category;
11: IEnumerable<string> categories = repository.Products
12: .Select(x => x.Category)
13: .Distinct()
14: .OrderBy(x => x);
15: return PartialView(categories);
16: }
1: public class Product
2: {
3: [HiddenInput(DisplayValue=false)]
4: public int ProductID { get; set; }
5:
6: [Required(ErrorMessage="Please enter a product name")]
7: public string Name { get; set; }
8:
9: [Required (ErrorMessage="Please enter a dscription")]
10: [DataType(DataType.MultilineText)]
11: public string Description { get; set; }
12:
13: [Required]
14: [Range(0.01,double.MaxValue,ErrorMessage="Please enter a positive price")]
15: public Decimal Price { get; set; }
16:
17: [Required(ErrorMessage="Please enter a category")]
18: public string Category { get; set; }
19:
20: public byte[] ImageData { get; set; }
21:
22: [HiddenInput(DisplayValue=false)]
23: public string ImageMimeType { get; set; }
24: }
1: public interface IProductRepository
2: {
3: IQueryable<Product> Products { get; }
4: void SaveProduct(Product product);
5: void DeleteProduct(Product product);
6: }