public ActionResult Create(Customer customer) { Customer foundCustomer = facade.GetCustomerRepository().Find(customer.ID); if (foundCustomer == null) { facade.GetCustomerRepository().Add(customer); } else { facade.GetCustomerRepository().Edit(customer); } Order order = new Order(); ShoppingCart cart = Session["ShoppingCart"] as ShoppingCart; if (cart == null) { cart = new ShoppingCart(); } foreach (var item in cart.OrderLines) { order.OrderLines.Add(item); } order.Customer = customer; facade.GetOrderRepository().Add(order); Session["ShoppingCart"] = cart; return Redirect("Confirmation"); }
public void Edit(Order order) { using (var ctx = new MovieShopContext()) { var dbOrder = Find(order.ID, ctx); dbOrder.Date = order.Date; ctx.SaveChanges(); } }
//Addding Order, making sure to attach customer, such no new customer would be made and use existing customer instead public void Add(Order order) { using (var ctx = new MovieShopContext()) { ctx.Customers.Attach(order.Customer); order.OrderLines.ForEach(x => ctx.Movies.Attach(x.Movie)); ctx.Orders.Add(order); ctx.SaveChanges(); } }
public ActionResult Edit(Order order) { facade.GetOrderRepository().Edit(order); return Redirect("Index"); }
public ActionResult Create(Order order) { facade.GetOrderRepository().Add(order); return Redirect("Index"); }