Ejemplo n.º 1
0
        public ActionResult EditItem(Item updateItem)
        {
            {
                CoffeeShopDBEntities2 ORM = new CoffeeShopDBEntities2();

                Item OldItem = ORM.Items.Find(updateItem.Name);

                if (OldItem != null && ModelState.IsValid)
                {
                    OldItem.Name        = updateItem.Name;
                    OldItem.Description = updateItem.Description;
                    OldItem.Quantity    = updateItem.Quantity;
                    OldItem.Price       = updateItem.Price;


                    ORM.Entry(OldItem).State = System.Data.Entity.EntityState.Modified;

                    ORM.SaveChanges();

                    ViewBag.Message = "Updates have been completed!";
                    return(View());
                }
                else
                {
                    ViewBag.ErrorMessage = "Something went wrong! Please try again!";
                    return(View("Error"));
                }
            }
        }
Ejemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "Name,Description,Quantity,Price")] Item item)
 {
     if (ModelState.IsValid)
     {
         db.Entry(item).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(item));
 }