Beispiel #1
0
        public IActionResult Index()
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            IEnumerable <Movie>         myMovies    = _myMovieService.GetByUserId(userId);
            IEnumerable <MoviePlaylist> myPlaylists = _myMoviePlaylistService.GetByUserId(userId);

            List <MyMediaMoviesViewModel> movieVMs = new List <MyMediaMoviesViewModel>();

            foreach (var movie in myMovies)
            {
                string genres = _movieGenreService.GetGenresByMovieId(movie.Id) != null?string.Join(",", _movieGenreService.GetGenresByMovieId(movie.Id).Select(x => x.Naam)) : "Geen genres";

                int ratingAvg = movie.RatingReviews != null && movie.RatingReviews.Where(r => r.MovieId == movie.Id).Select(r => r.Rating).Count() != 0 ?
                                movie.RatingReviews.Where(rat => rat.MovieId == movie.Id && rat.Rating > -1).Select(r => r.Rating).Sum()
                                / movie.RatingReviews.Where(rat => rat.MovieId == movie.Id && rat.Rating > -1).Count() : -1;

                int aantalGezien = movie.UserMovieGezienStatus != null?
                                   movie.UserMovieGezienStatus.Where(s => s.MovieId == movie.Id && s.MovieGezienStatus != null && s.MovieGezienStatusId == 2).Count() : 0;

                movieVMs.Add(new MyMediaMoviesViewModel
                {
                    Id               = movie.Id,
                    Titel            = movie.Titel,
                    AantalGezien     = aantalGezien,
                    Rating           = ratingAvg,
                    Genres           = genres,
                    MyRating         = _movieRatingReviewService.RatingByUserIdAndMovieId(userId, movie.Id),
                    ReviewGeschreven = _movieRatingReviewService.CheckIfReviewGeschrevenByUserIdForMovieId(userId, movie.Id)
                });
            }

            List <MyMediaMoviePlaylistsViewModel> playlistVMs = new List <MyMediaMoviePlaylistsViewModel>();

            foreach (var pl in myPlaylists)
            {
                playlistVMs.Add(new MyMediaMoviePlaylistsViewModel
                {
                    Id        = pl.Id,
                    Naam      = pl.Naam,
                    Speelduur = _moviePlaylistService.TotaleSpeelduur(pl.Id),
                    Aantal    = _moviePlaylistService.AantalMoviesInPlaylist(pl.Id),
                    Publiek   = pl.Publiek
                });
            }


            MyMediaViewModel vm = new MyMediaViewModel {
                MyMovies    = movieVMs,
                MyPlaylists = playlistVMs
            };

            return(View(vm));
        }
        public IActionResult Index()
        {
            IEnumerable <MoviePlaylist>   playlistsFromDb = _playlistService.Get();
            List <MoviePlaylistViewModel> vm = new List <MoviePlaylistViewModel>();

            foreach (var pl in playlistsFromDb)
            {
                vm.Add(new MoviePlaylistViewModel {
                    Naam = pl.Naam, Aantal = _playlistService.AantalMoviesInPlaylist(pl.Id), Id = pl.Id, Speelduur = _playlistService.TotaleSpeelduur(pl.Id)
                });
            }

            return(View(vm));
        }