Example #1
0
        public void addPriceForm_InsertItem()
        {
            var item = new FrontierAg.Models.Price();

            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                // Save changes here
                using (FrontierAg.Models.ProductContext db = new FrontierAg.Models.ProductContext())
                {
                    db.Prices.Add(item);
                    db.SaveChanges();
                }
            }
        }
Example #2
0
 // The id parameter name should match the DataKeyNames value set on the control
 public void PricesGrid_UpdateItem(int PriceId)
 {
     FrontierAg.Models.Price item = null;
     item = _db.Prices.Find(PriceId);
     // Load the item here, e.g. item = MyDataLayer.Find(id);
     if (item == null)
     {
         // The item wasn't found
         ModelState.AddModelError("", String.Format("Item with id {0} was not found", PriceId));
         return;
     }
     TryUpdateModel(item);
     if (ModelState.IsValid)
     {
         // Save changes here, e.g. MyDataLayer.SaveChanges();
         _db.SaveChanges();
     }
 }