Exemple #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));
        }
Exemple #2
0
        public ActorDto GetActorById(int id)
        {
            var actorById = filmFulDbContext.Actor
                            .Where(a => a.Id == id)
                            .SingleOrDefault();

            return(actorById == null ? null : DataTypeConversionUtils.ActorToActorDto(actorById));
        }
Exemple #3
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));
        }
Exemple #4
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);
            }
        }