public ActionResult Buy(long id)
 {
     if (HttpContext.Session.GetString("Cart") == null || HttpContext.Session.GetString("Cart") == "")
     {
         List <OrderViewModel> cart = new List <OrderViewModel>();
         cart.Add(new OrderViewModel
         {
             Movie    = service.AllMovies().Where(s => s.Id.Equals(id)),
             Quantity = 1
         });
         HttpContext.Session.SetString("Cart", JsonSerializer.Serialize(cart));
         HttpContext.Session.SetInt32("CartCounter", cart.Count());
     }
     else
     {
         string cartStr             = HttpContext.Session.GetString("Cart");
         List <OrderViewModel> cart = JsonSerializer.Deserialize <List <OrderViewModel> >(cartStr);
         if (Exist(id))
         {
             return(RedirectToAction("", "Movie"));
         }
         else
         {
             cart.Add(new OrderViewModel
             {
                 Movie    = service.AllMovies().Where(s => s.Id.Equals(id)),
                 Quantity = 1
             });
         }
         HttpContext.Session.SetString("Cart", JsonSerializer.Serialize(cart));
         HttpContext.Session.SetInt32("CartCounter", cart.Count());
     }
     return(RedirectToAction("", "Movie"));
 }
        public IActionResult Index()
        {
            ViewBag.ShowCart = true;
            HttpContext.Session.SetString("Movies", JsonSerializer.Serialize(service.AllMovies()));
            HttpContext.Session.SetString("OrderedMovies", JsonSerializer.Serialize(service.AllMovies().OrderBy(movie => movie.Title)));
            string        movies    = HttpContext.Session.GetString("Movies");
            List <Movies> movieList = JsonSerializer.Deserialize <List <Movies> >(movies);

            HttpContext.Session.SetString("RandomMovie", JsonSerializer.Serialize(service.GetRandomMovie()));
            string        randomMovie     = HttpContext.Session.GetString("RandomMovie");
            List <Movies> randomMovieList = JsonSerializer.Deserialize <List <Movies> >(randomMovie);

            if (HttpContext.Session.GetInt32("CartCounter") == null)
            {
                HttpContext.Session.SetInt32("CartCounter", 0);
            }
            int counter = (int)HttpContext.Session.GetInt32("CartCounter");

            return(View(movieHandler.CreateHomepage(movieList, randomMovieList, counter)));
        }