Beispiel #1
0
 // The id parameter name should match the DataKeyNames value set on the control
 public void productsGrid_DeleteItem(int id)
 {
     using (var context = new VatplanEntities())
     {
         var item = new Products()
         {
             Id = id
         };
         context.Entry(item).State = System.Data.Entity.EntityState.Deleted;
         try
         {
             context.SaveChanges();
         }
         catch (Exception ex)
         {
             ModelState.AddModelError("", string.Format("Product o identyfikatorze {0} nie został znaleziony."
                                                        , id));
         }
     }
 }
Beispiel #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);
                }
            }
        }
Beispiel #3
0
 private void PrepareProductSelectDatas(VatplanEntities context)
 {
     ViewData["UnitsId"]   = new SelectList(context.UnitsOfMeasure.ToList(), "Id", "Name");
     ViewData["VatRateId"] = new SelectList(context.VatRates.ToList(), "Id", "Name");
 }