public async Task <IActionResult> GetUserFavouriteTvSeries()
        {
            var user     = User.Identity.Name;
            var response = await _userFavouriteTvShowsService.GetUserFavouriteTvSeries(user);

            if (response.ErrorOccurred)
            {
                return(BadRequest(response));
            }

            return(Ok(response));
        }
Exemple #2
0
        public async Task <ResponseDto <TvShowResponse> > GetTvSeries(int tvSeriesId, string userId)
        {
            var response       = new ResponseDto <TvShowResponse>();
            var tvSeriesExists = await _tvShowRepository.ExistAsync(x => x.Id == tvSeriesId);

            if (userId == null)
            {
                response.AddError(Model.Account, Error.account_Login);
                return(response);
            }

            if (!tvSeriesExists)
            {
                response.AddError(Model.TvShow, Error.tvShow_NotFound);
                return(response);
            }

            var tvSeries = await _tvShowRepository.GetByAsync(x => x.Id == tvSeriesId, x => x.Seasons, x => x.TvSeriesRatings);

            await _tvShowRepository.LoadRelatedCollection(tvSeries, x => x.Seasons, x => x.Episodes);

            var mappedTvSeries = _mapper.Map <TvShowResponse>(tvSeries);

            var assignments = await _actorAssignmentService.GetTvShowAssignments(tvSeriesId);

            var categoryAssignments = await _tvShowCategoriesAssignmentsService.GetTvShowsCategories(tvSeriesId);

            mappedTvSeries.Actors     = assignments.DtoObject;
            mappedTvSeries.Categories = categoryAssignments.DtoObject;

            if (userId != null)
            {
                var userFavourites = await _userFavouriteTvShowsService.GetUserFavouriteTvSeries(userId);

                mappedTvSeries.IsFavourite = userFavourites.DtoObject.Any(x => x.Id == tvSeriesId);

                var userRating = await _ratingService.GetTvSeriesRatingForUser(userId, tvSeriesId);

                if (!userRating.ErrorOccurred)
                {
                    mappedTvSeries.UserRatingDto = new TvSeriesRatingsDto
                    {
                        Id      = userRating.DtoObject.Id,
                        Average = userRating.DtoObject.Average,
                        Music   = userRating.DtoObject.Music,
                        Effects = userRating.DtoObject.Effects,
                        Story   = userRating.DtoObject.Story
                    };
                }
            }

            foreach (var season in mappedTvSeries.Seasons)
            {
                var seasonWatched = true;
                foreach (var episode in season.Episodes)
                {
                    if (await _userWatchedEpisodeService.CheckIfEpisodeWatched(episode.Id, userId))
                    {
                        episode.Watched = true;
                    }
                    else
                    {
                        seasonWatched = false;
                    }
                }

                season.Watched = seasonWatched;
            }

            response.DtoObject = mappedTvSeries;

            return(response);
        }