public ActionResult AjaxAddOrder(int customerId) { if (ModelState.IsValid) { var context = new SampleEntities(); var customer = context.Customers.Single(c => c.ID == customerId); var order = new Order(); try { UpdateModel(order); customer.Orders.Add(order); context.SaveChanges(); } catch (Exception e) { Response.StatusCode = 500; Response.AppendHeader("message", "There was an issue adding order to customer \"" + customer.FirstName + " " + customer.LastName + "\". Please contact tech support with this message: " + Utility.GetInnermostException(e).Message); } } return View(new GridModel(GetOrders(customerId))); }
/// <summary> /// Create a new Order object. /// </summary> /// <param name="id">Initial value of the ID property.</param> /// <param name="customerID">Initial value of the CustomerID property.</param> /// <param name="orderChannelID">Initial value of the OrderChannelID property.</param> public static Order CreateOrder(global::System.Int32 id, global::System.Int32 customerID, global::System.Int32 orderChannelID) { Order order = new Order(); order.ID = id; order.CustomerID = customerID; order.OrderChannelID = orderChannelID; return order; }
/// <summary> /// Deprecated Method for adding a new object to the Orders EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToOrders(Order order) { base.AddObject("Orders", order); }