Exemplo n.º 1
0
        //GET: /Actor/Details/5
        public async Task <IActionResult> Details(ushort id = 0)
        {
            var actorFilms = new ActorIndexData();

            //ovo bi trebalo učitat sve actore i njihove veze s filmactor i film tablicama
            actorFilms.Actors = await _context.Actor
                                .Include(i => i.FilmActor)
                                .ThenInclude(i => i.Film)
                                .AsNoTracking()
                                .ToListAsync();


            //ovdje je naštimano da app radi, ali način ziher nije optimalan i ispravan

            //učitaj actora za prikaz
            actorFilms.Actors = actorFilms.Actors.Where(i => i.ActorId == id).ToList();

            //učitaj actora za daljnju pretragu po filmactorima
            Actor actor = actorFilms.Actors.Where(i => i.ActorId == id).Single();

            //učitaj filmactora za daljnju pretragu po filmovima
            actorFilms.FilmActors = actor.FilmActor.Where(i => i.ActorId == id).ToList();

            //učitaj sve filmove za određenog filmaktora
            actorFilms.Films = actorFilms.FilmActors.Select(x => x.Film);

            //učitaj distinktne naslove filmova
            actorFilms.Title = actorFilms.Films.Select(x => x.Title).Distinct().ToList();

            return(View(actorFilms));
        }
        // GET: Actors
        public async Task <IActionResult> Index(int?id, int?movieID)
        {
            var viewModel = new ActorIndexData();

            viewModel.Actors = await _context.Actors
                               .Include(i => i.AppearanceMovies)
                               .ThenInclude(i => i.Movie)
                               .ThenInclude(i => i.Studio)
                               //.ThenInclude(i => i.Customer)
                               .AsNoTracking()
                               .OrderBy(i => i.Name)
                               .ToListAsync();

            if (id != null)
            {
                ViewData["ActorID"] = id.Value;
                Actor actor = viewModel.Actors.Where(
                    i => i.ActorID == id.Value).Single();
                viewModel.Movies = actor.AppearanceMovies.Select(s => s.Movie);
            }
            if (movieID != null)
            {
                ViewData["MovieID"] = movieID.Value;
                viewModel.Studios   = viewModel.Movies.Where(x => x.MovieID == movieID).Select(s => s.Studio);
            }
            return(View(viewModel));
        }