public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();
            TryUpdateModel(order);

            try
            {
                order.Username = User.Identity.Name;
                order.OrderDate = DateTime.Now;

                // Inserir encomenda na base de dados
                storeDB.AddToOrders(order);
                storeDB.SaveChanges();

                // Processar a encomenda
                cart = ShoppingCart.GetCart(this.HttpContext);
                cart.CreateOrder(order);

                return RedirectToAction("Complete",
                    new { id = order.OrderId });
            }
            catch
            {
                return RedirectToAction("Index", "ShoppingCart");
            }
        }
Exemplo n.º 2
0
        public void GetCartId_ReturnsCartIdFromCookies()
        {
            // Arrange
            var cartId = "cartId_A";

            var httpContext = new DefaultHttpContext();
            httpContext.SetFeature<IRequestCookiesFeature>(new CookiesFeature("Session=" + cartId));

            var cart = new ShoppingCart(new MusicStoreContext());

            // Act
            var result = cart.GetCartId(httpContext);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(cartId, result);
        }
Exemplo n.º 3
0
 public static ShoppingCart GetCart(MusicStoreContext db, HttpContext context)
 {
     var cart = new ShoppingCart(db);
     cart.ShoppingCartId = cart.GetCartId(context);
     return cart;
 }
Exemplo n.º 4
0
 public static ShoppingCart GetCart(HttpContextBase context)
 {
     var cart = new ShoppingCart();
     cart.ShoppingCartId = cart.GetCartId(context);
     return cart;
 }