public ActionResult AjaxAddCustomer(string lastName, string firstName) { if (ModelState.IsValid) { try { var context = new SampleEntities(); var customer = new Customer(); UpdateModel(customer); context.Customers.AddObject(customer); context.SaveChanges(); } catch (Exception e) { Response.StatusCode = 500; Response.AppendHeader("message", "There was an issue adding customer \"" + firstName + " " + lastName + "\". Please contact tech support with this message: " + Utility.GetInnermostException(e).Message); } } return View(new GridModel(GetCustomers())); }
/// <summary> /// Create a new Customer object. /// </summary> /// <param name="id">Initial value of the ID property.</param> /// <param name="accountNumber">Initial value of the AccountNumber property.</param> /// <param name="lastName">Initial value of the LastName property.</param> /// <param name="firstName">Initial value of the FirstName property.</param> public static Customer CreateCustomer(global::System.Int32 id, global::System.String accountNumber, global::System.String lastName, global::System.String firstName) { Customer customer = new Customer(); customer.ID = id; customer.AccountNumber = accountNumber; customer.LastName = lastName; customer.FirstName = firstName; return customer; }
/// <summary> /// Deprecated Method for adding a new object to the Customers EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCustomers(Customer customer) { base.AddObject("Customers", customer); }