public void SaveCustomer(Customer customer) { if (this.ModelState.IsValid) { using (var db = new ProductsContext()) { db.Customers.Add(customer); db.SaveChanges(); this.Response.Redirect("~/Customers.aspx"); } } }
public void UpdateCustomer(int id) { using (var db = new ProductsContext()) { var customer = db.Customers.Find(id); this.TryUpdateModel(customer); if (this.ModelState.IsValid) { db.SaveChanges(); } } }