Exemple #1
0
        //id'si verilen filmi getirme
        public IDataResult <MovieApiResult> GetMovieFromApiById(int movieId)
        {
            try
            {
                HttpWebRequest apiRequest = WebRequest.CreateHttp(string.Format("https://api.themoviedb.org/3/movie/{0}?api_key={1}", movieId, apiKey)) as HttpWebRequest;

                string apiResponse = "";

                using (HttpWebResponse response = apiRequest.GetResponse() as HttpWebResponse)
                {
                    StreamReader reader = new StreamReader(response.GetResponseStream());
                    apiResponse = reader.ReadToEnd();
                }

                MovieApiResult rootObject = JsonConvert.DeserializeObject <MovieApiResult>(apiResponse);

                return(new SuccessDataResult <MovieApiResult>(rootObject));
            }
            catch (Exception ex)
            {
                return(new ErrorDataResult <MovieApiResult>(ex.Message));
            }
        }
Exemple #2
0
        /// <summary>
        /// Returns the movie with the given id from the API
        /// </summary>
        /// <param name="id">Id of the movie</param>
        /// <returns>A Movie object</returns>
        private Movie GetMovieByIdFromAPI(int id)
        {
            //Retrieve the movie from the API
            IRestResponse movieResponse = itemApiRepo.GetMovieById(id);

            //Convert the response to a movie object
            MovieApiResult apiMovie = JsonConvert.DeserializeObject <MovieApiResult>(movieResponse.Content);

            //Retrieve the credits (Person objects) from the API
            IRestResponse creditsResponse = itemApiRepo.GetCreditsByMovieId(id);

            //Convert the response to a MovieCreditsRoot object
            CreditsRoot movieCreditsRoot = JsonConvert.DeserializeObject <CreditsRoot>(creditsResponse.Content);

            Movie movie = new Movie {
                Id          = apiMovie.Id,
                Title       = apiMovie.Title,
                Description = apiMovie.Description,
                ReleaseDate = apiMovie.ReleaseDate,
                PosterPath  = apiMovie.PosterURL,
                BackdropURL = apiMovie.BackdropURL
            };

            movie.ItemGenres = new List <ItemGenre>();

            foreach (Genre genre in apiMovie.Genres)
            {
                movie.ItemGenres.Add(new ItemGenre {
                    ItemId = movie.Id, GenreId = genre.Id, Item = movie, Genre = genre
                });
            }

            //Add all people to the movie
            movie.ItemCrewMembers = new List <ItemCrewMember>();

            foreach (CrewMemberResult crewMember in movieCreditsRoot.Crew)
            {
                movie.ItemCrewMembers.Add(
                    new ItemCrewMember {
                    ItemId       = movie.Id,
                    CrewMemberId = crewMember.Id,
                    Item         = movie,
                    CrewMember   = new CrewMember {
                        Id = crewMember.Id, Name = crewMember.Name
                    },
                    Job = crewMember.Job
                }
                    );
            }

            movie.ItemCastMembers = new List <ItemCastMember>();

            foreach (CastMemberResult castMember in movieCreditsRoot.Cast)
            {
                movie.ItemCastMembers.Add(
                    new ItemCastMember {
                    ItemId       = movie.Id,
                    CastMemberId = castMember.Id,
                    Item         = movie,
                    CastMember   = new CastMember {
                        Id = castMember.Id, Name = castMember.Name
                    },
                    Character = castMember.Character
                }
                    );
            }

            return(movie);
        }