public ActionResult EditConfirm(
            [Bind(Include = "Id,Priority,Name,Quantity,Status")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(Redirect("/"));
        }
Exemplo n.º 2
0
        public ActionResult EditConfirm(int?id, Product productModel)
        {
            if (ModelState.IsValid)
            {
                using (var db = new ShoppingListDbContext())
                {
                    var product = productModel;
                    db.Entry(product).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        public ActionResult EditConfirm(int?id, Product productModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Create"));
            }

            using (var db = new ShoppingListDbContext())
            {
                var product = db.Products.First(p => p.Id == id);
                product.Name     = productModel.Name;
                product.Priority = productModel.Priority;
                product.Quantity = productModel.Quantity;
                product.Status   = productModel.Status;

                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
        public ActionResult EditConfirm(int?id, Product productModel)
        {
            using (var db = new ShoppingListDbContext())
            {
                var product = db.Products
                              .Where(p => p.Id == id)
                              .First();

                if (product == null)
                {
                    return(HttpNotFound());
                }

                product.Priority = productModel.Priority;
                product.Name     = productModel.Name;
                product.Quantity = productModel.Quantity;
                product.Status   = productModel.Status;

                db.Entry(product).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }