Exemplo n.º 1
0
        private void movieBindingNavigatorSaveItem_Click_1(object sender, EventArgs e)
        {
            int error = 0;

            if (validateAllFields())
            {
                MessageBox.Show("Please fill all fields for movie information.");
                return;
            }
            if (addOrEdit == 0)
            {
                error = updateOrInsertCasts(addOrEdit);
            }
            else if (addOrEdit == 1)
            {
                int movieId = 0;
                try
                {
                    movieId = Int32.Parse(idTextBox.Text);
                }
                catch (Exception a)
                {
                    MessageBox.Show("Id should be numeric for movie.");
                    error = 1;
                }
                if (dbController.checkIfMovieInDatabase(movieId))
                {
                    MessageBox.Show("Movie with the same ID already exists.");
                    error = 1;
                }
                else
                {
                    error              = updateOrInsertCasts(addOrEdit);
                    addOrEdit          = 0;
                    idTextBox.ReadOnly = true;
                }
            }
            if (error == 0)
            {
                this.Validate();
                this.movieBindingSource.EndEdit();
                this.tableAdapterManager.UpdateAll(this.movieDBDataSet);
            }
        }
Exemplo n.º 2
0
        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);
        }