public ActionResult Confirmation(ShoppingCart shoppingCart) { // TODO 8.0: Slow network. Thread.Sleep(2000); Order order = SaveAsOrder(shoppingCart); OrderProcessingService.SendProcessOrderMessage(order.OrderId); ViewBag.Message = "Thank you for your order."; return View(new Confirmation { Item = shoppingCart.Item, ConfirmationNumber = "CN" + order.OrderId }); }
private static Order SaveAsOrder(ShoppingCart shoppingCart) { Order order; using (var context = new OrderContext()) { // TODO 8.3: Look for existing order by uniquifier. var matchingOrders = from o in context.Orders where o.Uniquifier == shoppingCart.Uniquifier select o; order = matchingOrders.FirstOrDefault(); if (order != null) return order; order = new Order { Item = shoppingCart.Item, // TODO 8.4: Copy uniquifier. Uniquifier = shoppingCart.Uniquifier }; context.Orders.Add(order); context.SaveChanges(); } return order; }