示例#1
0
        public void grdProduits_UpdateItem(int ProductID)
        {
            DemoWebForms.Models.Product item = db.Products.Find(ProductID);

            if (item == null)
            {
                // The item wasn't found
                ModelState.AddModelError("", String.Format("Item {0} n'est pas trouvé", ProductID));
                return;
            }
            Page.TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                db.SaveChanges();
            }
        }
示例#2
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void grdProduits_DeleteItem(int ProductID)
        {
            DemoWebForms.Models.Product item = db.Products.Find(ProductID);

            if (item == null)
            {
                // The item wasn't found
                ModelState.AddModelError("", String.Format("Item {0} n'est pas trouvé", ProductID));
                return;
            }
            db.Products.Remove(item);
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                ModelState.AddModelError("", String.Format("Item {0} a été modifié depuis sa lecture", ProductID));
            }
            catch (DbUpdateException ex)
            {
                ModelState.AddModelError("", String.Format("Item {0} n'a pas pu être enlevé", ProductID));
            }
        }