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"); } }
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); }
public static ShoppingCart GetCart(MusicStoreContext db, HttpContext context) { var cart = new ShoppingCart(db); cart.ShoppingCartId = cart.GetCartId(context); return cart; }
public static ShoppingCart GetCart(HttpContextBase context) { var cart = new ShoppingCart(); cart.ShoppingCartId = cart.GetCartId(context); return cart; }