public IActionResult Index()
        {
            var cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart");

            CartVM = new cartVM()
            {
                Items = cart
            };

            return(View(CartVM));
        }
        public IActionResult CheckOut()
        {
            var userId = _userManager.GetUserId(this.User);

            if (userId != null)
            {
                List <Item> cart = new List <Item>();
                cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart");

                cartVM CartVM = new cartVM
                {
                    Items = cart
                };

                return(View(CartVM));
            }

            return(LocalRedirect("/Identity/Account/Login"));
        }
        public IActionResult Checkout(cartVM CartVM)
        {
            if (ModelState.IsValid)
            {
                Product     product = new Product();
                List <Item> cart    = new List <Item>();
                cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart");

                CartVM.OrderHeader.OrderDate = DateTime.Now;
                CartVM.OrderHeader.Status    = "Submitted";

                foreach (var item in cart)
                {
                    CartVM.OrderHeader.OrderTotal += (item.Product.Price * item.Quantity);
                }
                var userId = _userManager.GetUserId(this.User);

                CartVM.OrderHeader.UserId = userId;
                _iOrderH.Add(CartVM.OrderHeader);

                foreach (var item in cart)
                {
                    product = _iProd.GetFirstOrDefault(item.Product.Id);
                    OrderDetails orderDetails = new OrderDetails
                    {
                        OrderHeaderId   = CartVM.OrderHeader.Id,
                        ProductId       = item.Product.Id,
                        ProductQuantity = item.Quantity,
                        ProductName     = item.Product.Name,
                        ProductPrice    = (item.Product.Price * item.Quantity)
                    };
                    product.Quantity = product.Quantity - item.Quantity;

                    _iProd.Update(product);
                    _iOrderD.Add(orderDetails);
                }
                cart.Clear();
                SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart);

                return(RedirectToAction("OrderConfirmation", "Cart", new { id = CartVM.OrderHeader.Id }));
            }
            return(View(nameof(Index)));
        }