public ActionResult DeleteProduct(int id) { using (var entities = new Models.BeerModel()) { var product = entities.Products.FirstOrDefault(x => x.Id == id); entities.Products.Remove(product); entities.SaveChanges(); return(RedirectToAction("Index", "Category")); } }
public ActionResult EditCategory(ViewModels.EditCategoryViewModel model) { if (!ModelState.IsValid) { return(View(model)); } using (var entities = new Models.BeerModel()) { var cat = entities.Categories.FirstOrDefault(x => x.Id == model.Id); cat.Name = model.Name; entities.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult NewCategory(ViewModels.NewCategoryViewModel model) { if (!ModelState.IsValid) { return(View(model)); } using (var entities = new Models.BeerModel()) { var newCat = new Category { Name = model.Name }; entities.Categories.Add(newCat); entities.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult EditProduct(ViewModels.EditProductViewModel modified) { SetupAvailableCatgoriesEdit(modified); if (!ModelState.IsValid) { return(View(modified)); } using (var entities = new Models.BeerModel()) { var model = entities.Products.FirstOrDefault(x => x.Id == modified.Id); model.Name = modified.Name; model.Price = modified.Price; model.Description = modified.Description; model.Category_Id = modified.Category_Id; model.PicURL = modified.PicURL; entities.SaveChanges(); return(RedirectToAction("Index", "Category")); } }