public async Task <ActionResult> CheckOut([Bind(Exclude = "creditCard")] CheckOut newHistory) { Cart myCart = (Cart)Session["Cart"]; if (myCart.myCart.Count == 0) { return(View("Index")); } if (ModelState.IsValid) { Session["Cart"] = null; DateTime today = DateTime.Now; AspNetUser user = await Utility.Util.getUser(HttpContext.User); newHistory.history.bh.userId = user.Id; newHistory.history.bh.buyingDate = today.ToString(); db.BuyingHistory.Add(newHistory.history.bh); await db.SaveChangesAsync(); BuyingHistory ttt = await db.BuyingHistory.OrderByDescending(i => i.buyingId).FirstOrDefaultAsync <BuyingHistory>(); BuyingHistoryItem historyItem; foreach (CartItem p in myCart.myCart) { historyItem = new BuyingHistoryItem(); historyItem.buyingId = ttt.buyingId; if (p.isBundle) { historyItem.productID = 1012; historyItem.bundleId = p.id; } else { historyItem.bundleId = 3; historyItem.productID = p.id; } historyItem.quantity = p.quantity; newHistory.history.bh.totalPrice += p.price * p.quantity; db.BuyingHistoryItems.Add(historyItem); } db.Entry(newHistory.history.bh).State = EntityState.Modified; await db.SaveChangesAsync(); //creditCard.card.userId = userId; return(RedirectToAction("Invoice", "BuyingHistories", new { id = ttt.buyingId })); } return(View(newHistory)); }
public async Task <ActionResult> Invoice(int id) { BuyingHistory history = await db.BuyingHistory.FindAsync(id); return(View(history)); }
private void buyinHistoryButton_Click(object sender, EventArgs e) { var history = new BuyingHistory(); history.Show(); }