Example #1
0
 // The id parameter name should match the DataKeyNames value set on the control
 public void productsGrid_UpdateItem(int id)
 {
     using (var context = new VatplanEntities())
     {
         PlanVat.Domain.DB.Products item = context.Products.Find(id);
         if (item == null)
         {
             // The item wasn't found
             ModelState.AddModelError("", String.Format("Produkt o identyfikatorze {0} nie został znaleziony", id));
             return;
         }
         TryUpdateModel(item);
         if (ModelState.IsValid)
         {
             // Save changes here, e.g. MyDataLayer.SaveChanges();
             context.SaveChanges();
         }
     }
 }
Example #2
0
        public void addProductForm_InsertItem()
        {
            var product = new PlanVat.Domain.DB.Products();

            TryUpdateModel(product);
            if (ModelState.IsValid)
            {
                try
                {
                    using (var context = new VatplanEntities())
                    {
                        context.Products.Add(product);
                        context.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Pole {0} jest wymagane...", ex);
                }
            }
        }