Beispiel #1
0
        public IActionResult Checkout([Bind("Orderid,OrderDate,Userid,OrderCount,OrderPrice,Gameid,Cardid,Eventgameid,DiscountRate")] Order order)
        {
            if (ModelState.IsValid)
            {
                List <Item> cart = getCartSession();

                foreach (var game in cart)
                {
                    Order saveOrder = new Order();

                    saveOrder.Userid     = order.Userid;
                    saveOrder.Cardid     = order.Cardid;
                    saveOrder.Gameid     = game.Game.Gameid;
                    saveOrder.OrderPrice = game.Game.Price * game.Quantity;
                    saveOrder.OrderCount = game.Quantity;
                    saveOrder.OrderDate  = DateTime.Now;

                    _context.Add(saveOrder);
                    _context.SaveChanges();
                }

                HttpContext.Session.Remove("cart");
                return(RedirectToAction(nameof(Confirmation)));
            }

            ViewData["UserId"] = _HttpContextAccessor.HttpContext.Session.GetString("Userid");
            ViewBag.Cardid     = new SelectList(_context.Creditcard, "Cardid", "Cardnumber");
            return(View(order));
        }