public override bool IsValid(object value) { var val = value as string; if (val == null) return true; CategoryRepo cr = new CategoryRepo(); if (cr.GetAllCategories().Any(c => c.Name.Equals(val))) return false; return true; }
// // GET: /Product/Create public ActionResult Create(int id) { CategoryRepo cr = new CategoryRepo(); if (cr.ValidateID(id)) { ProductModel p = new ProductModel(); p.Category = id; return View(p); } return RedirectToAction("Index", "Category"); }
// // GET: /Product/ public ActionResult Index(int? id) { if (id == null) return null; CategoryRepo cr = new CategoryRepo(); if(cr.ValidateID(id.Value)) { ViewData["category"] = id; return View(products.GetProductsFromCategory(id.Value)); } return RedirectToAction("Index", "Category"); }