Beispiel #1
0
        public async Task <List <TVShowAllViewModel> > GetAllTVShowsAsync(string userId = null)
        {
            var allTVShowsFromDb = await dbContext.TVShows.ToListAsync();

            var tvShowAllViewModel = mapper.Map <List <TVShow>, List <TVShowAllViewModel> >(allTVShowsFromDb);

            foreach (var tvShow in tvShowAllViewModel)
            {
                tvShow.Watchlisted = await watchlistService.TVShowIsInUserWatchlistAsync(userId, tvShow.Id);
            }

            return(tvShowAllViewModel);
        }
        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));
            }
        }