Exemplo n.º 1
0
 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...");
         }
     }
 }
Exemplo n.º 2
0
 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();
 }
Exemplo n.º 3
0
 public void SubmitOrder(Order order)
 {
     Guard.ArgumentNotNull(order, "order");
     CheckStock(order);
     this.OrderRepository.AddOrder(order);
 }