private void CheckStock(Order order) { foreach (var line in order.OrderLines) { if (this.ProductService.GetStock(line.ProductId) < line.Quantity) { throw new OutOfStockException("Out of stock..."); } } }
public ActionResult CheckOut([ModelBinder(typeof(ShoppingCartBinder))]ShoppingCart shoppingCart) { Guard.ArgumentNotNull(shoppingCart, "shoppingCart"); Order order = new Order { OrderId = Guid.NewGuid().ToString(), OrderTime = DateTime.Now, UserName = User.Identity.Name }; foreach (ShoppingCartItem item in shoppingCart.Items) { order.OrderLines.Add(new OrderLine { Order = order, OrderId = order.OrderId, ProductId = item.ProductId, Quantity = item.Quantity }); } this.OrderService.SubmitOrder(order); ShoppingCartBinder.Clear(); return View(); }
public void SubmitOrder(Order order) { Guard.ArgumentNotNull(order, "order"); CheckStock(order); this.OrderRepository.AddOrder(order); }