//Adding movie to database or just to the current instance private MovieConnector.Movie addMovieToDisplay(SearchMovie movie) { TMDbLib.Objects.Movies.Movie movie2 = client.GetMovieAsync(movie.Id).Result; List <string> ourGenres = new List <string>(); List <MovieConnector.Cast> ourCasts = new List <MovieConnector.Cast>(); foreach (Genre genre in movie2.Genres) { ourGenres.Add(genre.Name); } try { TMDbLib.Objects.Movies.Movie casts; casts = getCasts(movie.Id); int castCount = casts.Credits.Cast.Capacity; if (castCount > 5) { castCount = 5; } for (int i = 0; i < castCount; i++) { ourCasts.Add(new MovieConnector.Cast(casts.Credits.Cast[i].Id, casts.Credits.Cast[i].Character, casts.Credits.Cast[i].Name, casts.Credits.Cast[i].ProfilePath)); } } catch (Exception e) { } currentMovie = new MovieConnector.Movie(movie.Id, movie.Title, movie.Overview, movie.ReleaseDate.Value, movie.VoteAverage, movie.PosterPath, ourCasts, string.Join(",", ourGenres.ToArray()), movie2.Runtime.Value); return(currentMovie); }
//------------------------------------------------------------------------------------ private void SearchButton_Click(object sender, EventArgs e) { shortMList.Clear(); var mr = new MovieResponse(); try { DBConnect.GetResponse("s", Title.Text.Trim(), ref mr); } catch (Exception ex) { MessageBox.Show(ex.Message); MoreButton.Enabled = false; } SearchMovie ms = mr as SearchMovie; foreach (var item in ms.Search) { shortMList.Add(item); } MovieListBox.DataSource = null; MovieListBox.DataSource = shortMList; MoreButton.Enabled = true; MovieListBox.Focus(); MovieListBox.SelectedIndex = 0; if (Uri.IsWellFormedUriString(shortMList[0].Poster, UriKind.Absolute)) { Poster.Load(shortMList[0].Poster); } }
private MovieConnector.Movie addMovieToDatabase(SearchMovie movie) { if (dbController.checkIfMovieInDatabase(movie.Id)) { currentMovie = dbController.getMovieContent(movie.Id); } else { TMDbLib.Objects.Movies.Movie movie2 = client.GetMovieAsync(movie.Id).Result; List <Genre> genres = movie2.Genres; List <string> ourGenres = new List <string>(); TMDbLib.Objects.Movies.Movie casts; foreach (Genre genre in genres) { ourGenres.Add(genre.Name); } currentMovie = dbController.insertToMovie(movie.Id, movie.Title, movie.Overview, movie.ReleaseDate.Value, movie.VoteAverage, movie.PosterPath, string.Join(",", ourGenres.ToArray()), movie2.Runtime.Value); try { casts = getCasts(movie.Id); int castCount = casts.Credits.Cast.Capacity; if (castCount > 5) { castCount = 5; } for (int i = 0; i < castCount; i++) { if (!dbController.checkIfCastInDatabase(casts.Credits.Cast[i].Id)) { dbController.insertToCast(casts.Credits.Cast[i].Id, casts.Credits.Cast[i].Character, casts.Credits.Cast[i].Name, casts.Credits.Cast[i].ProfilePath); } dbController.insertCastToMovie(movie.Id, casts.Credits.Cast[i].Id); } } catch (Exception e) { } } return(currentMovie); }