Пример #1
0
        public IActionResult Index()
        {
            List <MovieRegisseurListViewModel> listVM            = new List <MovieRegisseurListViewModel>();
            IEnumerable <MovieRegisseur>       movieGenresFromDb = _movieRegisseurService.Get();

            foreach (var genre in movieGenresFromDb)
            {
                listVM.Add(new MovieRegisseurListViewModel
                {
                    Id   = genre.Id,
                    Naam = genre.Naam
                });
            }

            MovieRegisseurIndexViewModel vm = new MovieRegisseurIndexViewModel
            {
                ListVM = listVM
            };

            return(View(vm));
        }
Пример #2
0
        public IActionResult Index()
        {
            List <MovieListViewModel> movies       = new List <MovieListViewModel>();
            IEnumerable <Movie>       moviesFromDb = _movieService.Get();

            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            foreach (var movie in moviesFromDb)
            {
                string regisseurs = _regisseurService.GetRegisseursByMovieId(movie.Id).Count() != 0 ? string.Join(",", _regisseurService.GetRegisseursByMovieId(movie.Id).Select(x => x.Naam)) : "Geen regisseur";
                string genres     = _genreService.GetGenresByMovieId(movie.Id) != null?string.Join(",", _genreService.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;

                int heeftGezien = userId != null && movie.UserMovieGezienStatus.Any(s => s.UserId == userId) ?
                                  movie.UserMovieGezienStatus.SingleOrDefault(s => s.MovieId == movie.Id && s.UserId == userId).MovieGezienStatusId : 1;

                movies.Add(new MovieListViewModel
                {
                    Id           = movie.Id,
                    Titel        = movie.Titel,
                    Beschrijving = movie.Beschrijving,
                    Regisseurs   = regisseurs,
                    Genres       = genres,
                    AantalGezien = aantalGezien,
                    HeeftGezien  = heeftGezien,
                    Rating       = ratingAvg,
                });
            }

            List <SelectListItem> GezienStatusList = new List <SelectListItem>();

            foreach (var status in _GezienStatusService.Get())
            {
                GezienStatusList.Add(new SelectListItem {
                    Value = status.Id.ToString(), Text = status.Status
                });
            }
            List <SelectListItem> RatingList = new List <SelectListItem> {
                new SelectListItem {
                    Value = "0", Text = "Geen selectie"
                },
                new SelectListItem {
                    Value = "1", Text = "Up"
                },
                new SelectListItem {
                    Value = "2", Text = "Down"
                }
            };
            List <SelectListItem> genreList = new List <SelectListItem>();

            genreList.Add(new SelectListItem {
                Value = "0", Text = "Selecteer genre"
            });
            foreach (var gen in _genreService.Get())
            {
                genreList.Add(new SelectListItem {
                    Value = gen.Id.ToString(), Text = gen.Naam
                });
            }
            List <SelectListItem> regisseurList = new List <SelectListItem>();

            regisseurList.Add(new SelectListItem {
                Value = "0", Text = "Selecteer regisseur"
            });
            foreach (var reg in _regisseurService.Get())
            {
                regisseurList.Add(new SelectListItem {
                    Value = reg.Id.ToString(), Text = reg.Naam
                });
            }

            MovieFilterListViewModel model = new MovieFilterListViewModel
            {
                Movies        = movies,
                RegisseurList = regisseurList,
            };

            return(View(model));
        }