示例#1
0
 public RedirectToRouteResult ChangeQuantity(Cart cart, int productId, string returnUrl, int quantity=0)
 {
     if (quantity < 1) quantity = 1;
     var product = _repository.Products.FirstOrDefault(p => p.ProductID == productId);
     if (product != null) cart.ChangeQuantity(product, quantity);
     return RedirectToAction("Index", new {returnUrl});
 }
示例#2
0
        public void Can_Change_Quantity()
        {
            var p1 = new Product { ProductID = 1, Name = "P1", StandardCost= 100M };
            //   var p2 = new Product { ProductID = 2, Name = "P2", Price = 50M };
            var target = new Cart();

            target.AddItem(p1, 1);
            target.ChangeQuantity(p1, 5);
            Assert.AreEqual(target.Lines.ElementAt(0).Quantity, 5);
        }