public async Task <ActionResult <RelatedMovie> > PostRelatedMovie(RelatedMovie relatedMovie) { _context.RelatedMovie.Add(relatedMovie); await _context.SaveChangesAsync(); return(CreatedAtAction("GetRelatedMovie", new { id = relatedMovie.RealtedMovieId }, relatedMovie)); }
public async Task <ActionResult <Movie> > PostMovie([FromBody] URLDTO URL) { String movieID = Helper.MovieHelper.GetMovieFromLink(URL.URL); Movie newMovie = Helper.MovieHelper.GetMovieFromID(movieID); _context.Movie.Add(newMovie); await _context.SaveChangesAsync(); // We are creating a new context so that loading realted movies don't block the api. MovieDBContext tempContext = new MovieDBContext(); RelatedMoviesController realtedMoviesController = new RelatedMoviesController(tempContext); //// This will be executed in the background. Task addCaptions = Task.Run(async() => { List <RelatedMovie> relatedMovies = Helper.MovieHelper.GetRelatedMovies(movieID); for (int i = 0; i < relatedMovies.Count; i++) { RelatedMovie relatedMovie = relatedMovies.ElementAt(i); relatedMovie.MovieId = newMovie.MovieId; // posting related movies to the database await realtedMoviesController.PostRelatedMovie(relatedMovie); } }); return(CreatedAtAction("GetMovie", new { id = newMovie.MovieId }, newMovie)); }
public async Task <IActionResult> PutRelatedMovie(int id, RelatedMovie relatedMovie) { if (id != relatedMovie.RealtedMovieId) { return(BadRequest()); } _context.Entry(relatedMovie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RelatedMovieExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public static void ShowRelatedMovies(string imdbid, string title, string year) { if (!File.Exists(GUIGraphicsContext.Skin + @"\Trakt.Related.Movies.xml")) { // let user know they need to update skin or harass skin author GUIUtils.ShowOKDialog(GUIUtils.PluginName(), Translation.SkinOutOfDate); return; } RelatedMovie relatedMovie = new RelatedMovie { IMDbId = imdbid, Title = title, Year = Convert.ToInt32(string.IsNullOrEmpty(year) ? "0" : year) }; GUIRelatedMovies.relatedMovie = relatedMovie; GUIWindowManager.ActivateWindow((int)TraktGUIWindows.RelatedMovies); }
public static List <RelatedMovie> GetRelatedMovies(String movieID) { String APIKEY = "6910e659fc35ebb1a5f364f7477b8e3d"; String movieAPISimilarLink = "https://api.themoviedb.org/3/movie/" + movieID + "/similar?api_key=" + APIKEY; //Uses HTTP client to get the JSON from the web String movieInfoJSON = new WebClient().DownloadString(movieAPISimilarLink); dynamic jsonObj = JsonConvert.DeserializeObject <dynamic>(movieInfoJSON); List <RelatedMovie> relatedMovies = new List <RelatedMovie>(); // Storing the realted movies title and imdb link in a list for (int i = 0; i < jsonObj["results"].Count; i++) { // getting the imbd link by making an api call String id = jsonObj["results"][i].id; String movieAPILinkTwo = "https://api.themoviedb.org/3/movie/" + id + "?api_key=" + APIKEY + "&language=en-US"; String movieInfoJSONTwo = new WebClient().DownloadString(movieAPILinkTwo); dynamic jsonObjTwo = JsonConvert.DeserializeObject <dynamic>(movieInfoJSONTwo); String IMDBLink = jsonObjTwo.imdb_id; RelatedMovie realtedMovie = new RelatedMovie { RelatedMovieTitle = jsonObj["results"][i].title, RelatedImdblink = "https://www.imdb.com/title/" + IMDBLink }; relatedMovies.Add(realtedMovie); } Console.WriteLine("Hello"); return(relatedMovies); }