public async Task <ActionResult> CheckOut([Bind(Include = "Email,OrderNumber,FirstName,LastName,Date,Phone,Country,Address,Address2,City, CartId")] OrderDetails order) { if (!ModelState.IsValid) { ViewBag.Countries = new SelectList(Countries.GetAllShortNames(), "shortName"); return(View(order)); } var cart = (ShoppingCart)Session["ShoppingCart"]; bool OutOfStock = false; foreach (var item in cart.CartItems) { item.Product = await db.Products.FindAsync(item.ProductId); if (item.Quantity > item.Product.Quantity) { cart.CartItems.Remove(item); OutOfStock = true; } } if (OutOfStock == true) { Session["ShoppingCart"] = cart; ViewBag.Stock = "Some of the items on the cart became out of stock while you were shopping. Oops!!!"; return(RedirectToAction("ListCart")); } var items = cart.CartItems; cart.CartItems = null; db.ShoppingCarts.Add(cart); await db.SaveChangesAsync(); foreach (var item in items) { item.Product.Quantity -= item.Quantity; db.Entry(item.Product).State = EntityState.Modified; item.ShoppingCart = cart; item.CartId = cart.CartId; db.Carts.Add(item); await db.SaveChangesAsync(); } cart.CartItems = items; db.Entry <ShoppingCart>(cart).State = EntityState.Modified; await db.SaveChangesAsync(); order.ShoppingCart = cart; order.CartId = cart.CartId; order.Date = DateTime.Now; db.Orders.Add(order); await db.SaveChangesAsync(); ViewBag.Message = "Check out successfully"; return(RedirectToAction("Index")); }
private void MainFrm_Load(object sender, EventArgs e) { StatusChk_timer_Tick(null, null); phoneCountry_combobox.Items.AddRange(Countries.GetAllShortNames().ToArray()); LoadSettings(); }
public ActionResult Checkout() { ViewBag.Countries = new SelectList(Countries.GetAllShortNames(), "shortName"); return(View()); }