public ActionResult DeleteConfirmed(int id) { var product = new DAL.Repository.ProductRepository() .GetById(id) .FirstOrDefault(); new DAL.Repository.ProductRepository() .Remove(product); return(RedirectToAction("Index")); }
// GET: Products public ActionResult Index() { var products = new DAL.Repository.ProductRepository() .GetAll() .GroupBy(p => p.ProductName.Substring(0, 1)) .Select(p => new { k = p.Key, value = p }) .ToDictionary( p => p.k, p => p.value.Select( x => new Models.ProductMVC() { Id = x.Id, Name = x.ProductName })); return(View(products)); }
public ActionResult Edit([Bind(Include = "Id,Name")] Models.ProductMVC product) { if (ModelState.IsValid) { var item = new DAL.Repository.ProductRepository() .GetById(product.Id) .FirstOrDefault(); if (item != null) { item.ProductName = product.Name; new DAL.Repository.ProductRepository() .Update(item); return(RedirectToAction("Index")); } } return(View(product)); }
// GET: Products/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var productId = id ?? default(int); var product = new DAL.Repository.ProductRepository() .GetById(productId).Select(x => new Models.ProductMVC() { Id = x.Id, Name = x.ProductName }) .FirstOrDefault(); if (product == null) { return(HttpNotFound()); } return(View(product)); }