public async Task <IActionResult> Index()
 {
     return(View(await _repository.GetWatchHistoryUser(User.Identity.Name)));
 }
Пример #2
0
        public async Task <IActionResult> Index()
        {
            if (User.IsAuthenticated())
            {
                /******* NO CACHING + ASYNC *******/
                //var q1 = _repository.GetMostPopularMoviesOfAllTime();
                //var q2 = _repository.GetMostPopularMoviesOfLastNDays(14);
                //var q3 = _repository.GetWatchHistoryUser(User.Identity.Name);
                //var q4 = _repository.GetLatestMoviesAdded();
                //ViewData["WatchHistory"] = await q3;
                //ViewData["LatestMovies"] = await q4;
                //ViewData["MostPopularOfAllTime"] = await q1;
                //ViewData["MostPopularOfLastTwoWeeks"] = await q2;
                /******* END NO CACHING = ASYNC *******/


                /******* NO CACHING + SEQ *******/
                //ViewData["WatchHistory"] = await _repository.GetWatchHistoryUser(User.Identity.Name);
                //ViewData["LatestMovies"] = await _repository.GetLatestMoviesAdded();
                //ViewData["MostPopularOfAllTime"] = await _repository.GetMostPopularMoviesOfAllTime();
                //ViewData["MostPopularOfLastTwoWeeks"] = await _repository.GetMostPopularMoviesOfLastNDays(14);
                /******* END NO CACHING + SEQ *******/

                var q3 = _repository.GetWatchHistoryUser(User.Identity.Name);

                if (!_cache.Exists("MostPopularOfLastTwoWeeks"))
                {
                    var q2 = _repository.GetMostPopularMoviesOfLastNDays(14);
                    ViewData["MostPopularOfLastTwoWeeks"] = await q2;
                    _cache.Add("MostPopularOfLastTwoWeeks", JsonConvert.SerializeObject(ViewData["MostPopularOfLastTwoWeeks"]));
                }
                else
                {
                    ViewData["MostPopularOfLastTwoWeeks"] = JsonConvert.DeserializeObject <List <PopularMoviesViewModel> >(await _cache.Retrieve("MostPopularOfLastTwoWeeks"));
                }

                if (!_cache.Exists("MostPopularOfAllTime"))
                {
                    var q1 = _repository.GetMostPopularMoviesOfAllTime();
                    ViewData["MostPopularOfAllTime"] = await q1;
                    _cache.Add("MostPopularOfAllTime", JsonConvert.SerializeObject(ViewData["MostPopularOfAllTime"]));
                }
                else
                {
                    ViewData["MostPopularOfAllTime"] = JsonConvert.DeserializeObject <List <PopularMoviesViewModel> >(await _cache.Retrieve("MostPopularOfAllTime"));
                }

                if (!_cache.Exists("LatestMovies"))
                {
                    var q4 = _repository.GetLatestMoviesAdded();
                    ViewData["LatestMovies"] = await q4;
                    _cache.Add("LatestMovies", JsonConvert.SerializeObject(ViewData["LatestMovies"]));
                }
                else
                {
                    ViewData["LatestMovies"] = JsonConvert.DeserializeObject <List <PopularMoviesViewModel> >(await _cache.Retrieve("LatestMovies"));
                }


                ViewData["WatchHistory"] = await q3;

                //ViewData["MostPopularOfAllTime"] = new List<PopularMoviesViewModel>();
                //ViewData["MostPopularOfLastTwoWeeks"] = new List<PopularMoviesViewModel>();
                //ViewData["WatchHistory"] = new List<PopularMoviesViewModel>();;
                //ViewData["LatestMovies"] = new List<PopularMoviesViewModel>();;

                return(View());
            }

            return(RedirectToAction("Index", "Home"));
        }