Ejemplo n.º 1
0
        public IEnumerable <ActorDto> GetActorActorsByActorId(int id)
        {
            // First, get all movies actor has starred in.
            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
                    where actor.Id == id
                    select movie
                );

            // If actor has not been in any movie, he must not have ever starred in any film with anyone at all.
            if (actorMovies == null || !actorMovies.Any())
            {
                return(null);
            }

            // Second, get all actors that appeared in these movies - Excluding the actor in question and avoiding duplicates.
            var actorActors =
                (
                    from actor in filmFulDbContext.Actor
                    join action in filmFulDbContext.Action on actor.Id equals action.ActorId
                    join movie in actorMovies on action.MovieId equals movie.Id
                    where actor.Id != id
                    select actor
                ).Distinct();

            // If actor has never worked with other actors return null, else return actors.
            return((actorActors == null || !actorActors.Any()) ? null : DataTypeConversionUtils.ActorToActorDto(actorActors));
        }
Ejemplo n.º 2
0
        public IEnumerable <DirectorDto> GetDirectorDirectorsByDirectorId(int id)
        {
            // First, get all movies director has directed.
            var directorMovies =
                (
                    from director in filmFulDbContext.Director
                    join direction in filmFulDbContext.Direction on director.Id equals direction.DirectorId
                    join movie in filmFulDbContext.Movie on direction.MovieId equals movie.Id
                    where director.Id == id
                    select movie
                );

            // If director has not directed any movie, he must not have ever co-directed any film with anyone at all.
            if (directorMovies == null || !directorMovies.Any())
            {
                return(null);
            }

            // Second, get all directors that co-directed these movies - Excluding the director in question and avoiding duplicates.
            var directorDirectors =
                (
                    from director in filmFulDbContext.Director
                    join direction in filmFulDbContext.Direction on director.Id equals direction.DirectorId
                    join movie in directorMovies on direction.MovieId equals movie.Id
                    where director.Id != id
                    select director
                ).Distinct();

            // If director has never worked with other directors return null, else return directors.
            return((directorDirectors == null || !directorDirectors.Any()) ? null : DataTypeConversionUtils.DirectorToDirectorDto(directorDirectors));
        }
Ejemplo n.º 3
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).
                );
        }
Ejemplo n.º 4
0
        public ActorDto GetActorById(int id)
        {
            var actorById = filmFulDbContext.Actor
                            .Where(a => a.Id == id)
                            .SingleOrDefault();

            return(actorById == null ? null : DataTypeConversionUtils.ActorToActorDto(actorById));
        }
Ejemplo n.º 5
0
        public DirectorDto GetDirectorById(int id)
        {
            var directorById = filmFulDbContext.Director
                               .Where(d => d.Id == id)
                               .SingleOrDefault();

            return(directorById == null ? null : DataTypeConversionUtils.DirectorToDirectorDto(directorById));
        }
Ejemplo n.º 6
0
        public IEnumerable <DirectorDto> GetMovieDirectorsByMovieId(int id)
        {
            var movieDirectors = (from director in filmFulDbContext.Director
                                  join direction in filmFulDbContext.Direction on director.Id equals direction.DirectorId
                                  join movie in filmFulDbContext.Movie on direction.MovieId equals movie.Id
                                  where movie.Id == id
                                  select director)
                                 .OrderBy(di => di.Name);

            return((movieDirectors == null || !movieDirectors.Any()) ? null : DataTypeConversionUtils.DirectorToDirectorDto(movieDirectors));
        }
Ejemplo n.º 7
0
        public IEnumerable <ActorDto> GetMovieActorsByMovieId(int id)
        {
            var movieActors = (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
                               where movie.Id == id
                               select actor)
                              .OrderBy(ac => ac.Name);

            return((movieActors == null || !movieActors.Any()) ? null : DataTypeConversionUtils.ActorToActorDto(movieActors));
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
0
        public (IEnumerable <ActorDto>, int) GetAllActors(int pageSize, int pageIndex)
        {
            int rangeOkay = Utilities.checkRange(pageSize, pageIndex, filmFulDbContext.Actor.Count());

            if (rangeOkay == Utilities.ok)
            {
                return(
                    DataTypeConversionUtils.ActorToActorDto
                    (
                        ((from a in filmFulDbContext.Actor
                          select a)
                         .Skip(pageIndex * pageSize)
                         .Take(pageSize)
                        )
                    ), rangeOkay
                    );
            }
            else
            {
                return(null, rangeOkay);
            }
        }
Ejemplo n.º 10
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).
                );
        }