Exemplo n.º 1
0
        public async Task <List <MovieAllViewModel> > GetAllMoviesAsync(string userId = null)
        {
            var allMoviesFromDb = await dbContext.Movies.ToListAsync();

            var moviesAllViewModel = mapper.Map <List <Movie>, List <MovieAllViewModel> >(allMoviesFromDb);

            foreach (var movie in moviesAllViewModel)
            {
                movie.Watchlisted = await watchlistService.MovieIsInUserWatchlistAsync(userId, movie.Id);
            }

            return(moviesAllViewModel);
        }
        public async Task <IActionResult> Add(string id, string returnAction, string returnQuery)
        {
            var idIsValidMovieOrTVShowId = await watchlistService.IsValidMovieOrTVShowIdAsync(id);

            if (!idIsValidMovieOrTVShowId)
            {
                return(Redirect(GlobalConstants.redirectError));
            }

            var userId = await userService.GetUserIdFromUserNameAsync(User.Identity.Name);

            var itemType = await watchlistService.IsIdMovieOrTVShowIdAsync(id);

            if (itemType == GlobalConstants.Movie)
            {
                if (await watchlistService.MovieIsInUserWatchlistAsync(userId, id))
                {
                    return(Redirect(GlobalConstants.redirectError));
                }
                await watchlistService.AddMovieToUserWatchlistAsync(userId, id);

                return(Redirect(returnAction + returnQuery));
            }
            else if (itemType == GlobalConstants.TV_Show)
            {
                if (await watchlistService.TVShowIsInUserWatchlistAsync(userId, id))
                {
                    return(Redirect(GlobalConstants.redirectError));
                }
                await watchlistService.AddTVShowToUserWatchlistAsync(userId, id);

                return(Redirect(returnAction + returnQuery));
            }
            else
            {
                return(Redirect(GlobalConstants.redirectError));
            }
        }