예제 #1
0
        public (IEnumerable <MovieDto>, int) GetActorMoviesByActorId(int id, List <string> genres)
        {
            var actorMovies = (from actor in filmFulDbContext.Actor
                               join action in filmFulDbContext.Action on actor.Id equals action.ActorId
                               join movie in filmFulDbContext.Movie on action.MovieId equals movie.Id
                               join genre in filmFulDbContext.Genre on movie.Id equals genre.MovieId
                               where actor.Id == id
                               select new  { movie, genre }
                               ).ToList();

            if (actorMovies == null || !actorMovies.Any())
            {
                return(null, Utilities.notFound);
            }                                                                                                       // Actor has not starred in any film.

            var actorMoviesWithGenres = actorMovies
                                        .Select(m => m.movie)
                                        .Distinct();

            return
                (
                (
                    DataTypeConversionUtils.MovieToMovieDto(genres != null ?
                                                            actorMoviesWithGenres.Where(m => !genres.Except(m.Genre.Select(g => g.Genre1)).Any()) : // Movies where the genres list is a subset of each movie's genre list.
                                                            actorMoviesWithGenres,                                                                  // No genre filtering
                                                            true)
                ),                                                                                                                                  // Denotes whether to return the poster or not. Always true in this instance. (May be changed later)
                Utilities.ok                                                                                                                        // Code whether the data fetching was a success. Should be 200 (ok).
                );
        }
예제 #2
0
        public MovieDto GetMovieById(int id)
        {
            // Get movie genre(s) and movie itself in a single request.
            var movieAndGenresById =
                (
                    from movie in filmFulDbContext.Movie
                    join genre in filmFulDbContext.Genre on movie.Id equals genre.MovieId
                    where movie.Id == id
                    select new { movie, genre.Genre1 }
                ).ToList();

            if (movieAndGenresById == null || !movieAndGenresById.Any())
            {
                return(null);
            }

            var movieGenres = movieAndGenresById.Select(g => g.Genre1).ToList();
            var movieResult = movieAndGenresById.Select(m => m.movie).First();

            return(DataTypeConversionUtils.MovieToMovieDto(movieResult, movieGenres));
        }
예제 #3
0
        public (IEnumerable <MovieDto>, int) GetAllMovies(int pageSize, int pageIndex, bool poster, List <string> genres)
        {
            var moviesAndGenres =
                (
                    from movie in filmFulDbContext.Movie
                    join genre in filmFulDbContext.Genre on movie.Id equals genre.MovieId
                    select new { movie, genre, movieCount = filmFulDbContext.Movie.Count() }
                ).ToList();

            int rangeOkay = Utilities.checkRange(pageSize, pageIndex, moviesAndGenres.First().movieCount);

            if (rangeOkay != Utilities.ok)
            {
                return(null, rangeOkay);
            }

            var moviesWithGenres = moviesAndGenres
                                   .Select(m => m.movie)
                                   .Distinct()
                                   .Skip(pageIndex * pageSize)
                                   .Take(pageSize);

            // At this point the selected range (page) of films has been gathered.
            // If genres contains list of valid genres, the selected range is filtered for movies
            // which are of the genres present in the genres list. The sanitization of the input
            // genre list happens in the Movie service layer.
            return
                (
                DataTypeConversionUtils.MovieToMovieDto
                    (genres != null ?
                    moviesWithGenres.Where(m => !genres.Except(m.Genre.Select(g => g.Genre1)).Any()) :          // Movies where the genres list is a subset of each movie's genre list.
                    moviesWithGenres,                                                                           // No genre filtering.
                    poster),                                                                                    // Denotes whether to return the poster or not.
                rangeOkay                                                                                       // Code whether the pagination was a success. Should be 200 (ok).
                );
        }