//Delete //This method is in charge of deleting product objects based on the given ProductID public ActionResult Delete(int id) { //Delete all instances of the ShoppingCartProductID with this method Store.Data.Product P = new Store.Data.Product { ProductID = id }; db.Products.Attach(P); db.Products.Remove(P); //Try saving try { db.SaveChanges(); } //If saving does not work catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } //Pass the ShoppingCartID back to the Ajax function return(Json(new { newID = id })); }
public ActionResult Edit([Bind(Include = "ProductName,Description,IsPublished,Quantity,Price,ImageFile,DateCreated,CreatedBy,DateModified,ModifiedBy")] Store.Data.Product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Store.Data.Product product = db.Products.Find(id); if (product == null) { return(HttpNotFound()); } return(View(product)); }
public ActionResult AddImage() { Store.Data.Product p1 = new Store.Data.Product(); return(View(p1)); }