コード例 #1
0
        public IActionResult Add(int movieId)
        {
            var userId        = userManager.GetUserId(HttpContext.User);
            var existingMovie = watchlistData.GetWatchlistByMovie(movieId, userId);

            if (existingMovie == null)
            {
                var watchlist = new Watchlist
                {
                    MovieId = movieId,
                    UserId  = userId
                };

                watchlistData.AddMovieToWatchlist(watchlist);

                TempData["ResultMessage"] = "The movie has been added to your watchlist.";
                TempData["AlertClass"]    = "alert alert-success";
            }
            else
            {
                TempData["ResultMessage"] = "This movie already exists in your watchlist.";
                TempData["AlertClass"]    = "alert alert-danger";
            }


            return(RedirectToAction(nameof(Index)));
        }