public IActionResult Checkout(OrderServiceBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(View());
            }

            var username = User.Identity.Name;

            orderService.CreateOrder(model, username);

            return(RedirectToAction("Index", "Home"));
        }
        public void CreateOrder(OrderServiceBindingModel model, string username)
        {
            var user = this.context.Users
                       .Include(c => c.Cart)
                       .ThenInclude(p => p.Products)
                       .ThenInclude(p => p.Product)
                       .FirstOrDefault(u => u.UserName == username);

            var order = mapper.Map <OrderServiceBindingModel, PendingOrder>(model);

            order.Items = new List <CartItem>(user.Cart.Products);

            this.context.PendingOrders.Add(order);
            user.Cart.Products.Clear();
            this.context.SaveChanges();
        }