public void MigrateCart(string username) { // Associate shopping cart items with logged-in user var shoppingCart = checkoutEntities.Carts.Where(c => c.CartId == cartIdRetriever.GetTheCartId()); foreach (var item in shoppingCart) { item.CartId = username; } checkoutEntities.SaveChanges(); HttpContext.Current.Session[ShoppingCart.CartSessionKey] = username; }
public ActionResult AddressAndPayment(FormCollection values) { var order = new Order(); order.OrderDetails = new List <OrderDetail>(); try { // Updat the model UpdateModel(order); if (string.Equals(values["PromoCode"], PromoCode, StringComparison.OrdinalIgnoreCase) == false) { return(View(order)); } else { if (ModelState.IsValid) { // Promo Code supplied order.Username = User.Identity.Name; order.OrderDate = DateTime.Now; // Save Order storeDB.Orders.Add(order); storeDB.SaveChanges(); // Process the order //var cart = ShoppingCart.GetCart(this); var cart = cartRetriever.GetTheCurrentCart(); cart.CreateOrder(order); return(RedirectToAction("Complete", new { id = order.OrderId })); } else { throw new Exception("Model State is not valid!"); } } } catch { // Invalid -- redisplay with errors return(View(order)); } }