예제 #1
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);
        }
예제 #2
0
파일: Form1.cs 프로젝트: war-man/Movie-app
        private int updateOrInsertCasts(int addOrEdit2)
        {
            int error   = 0;
            int movieId = 0;

            try
            {
                movieId = Int32.Parse(idTextBox.Text);
            }
            catch (Exception a)
            {
                MessageBox.Show("Id should be numeric for movie.");
                return(1);
            }
            for (int i = 0; i < 5;)
            {
                i++;
                string character = "", name = "";
                int    castId = 0;
                byte[] image  = null;
                if (this.Controls.ContainsKey("idText" + i.ToString()))
                {
                    TextBox idText = this.Controls["idText" + i.ToString()] as TextBox;
                    if (idText != null)
                    {
                        try
                        {
                            if (idText.Text != "")
                            {
                                castId = Int32.Parse(idText.Text);
                            }
                        }
                        catch (Exception a)
                        {
                            MessageBox.Show("Id should be numeric for cast " + i);
                            error = 1;
                        }
                    }
                }
                if (this.Controls.ContainsKey("characterText" + i.ToString()))
                {
                    TextBox characterText = this.Controls["characterText" + i.ToString()] as TextBox;
                    if (characterText != null)
                    {
                        character = characterText.Text;
                    }
                }
                if (this.Controls.ContainsKey("nameText" + i.ToString()))
                {
                    TextBox nameText = this.Controls["nameText" + i.ToString()] as TextBox;
                    if (nameText != null)
                    {
                        name = nameText.Text;
                    }
                }
                if (this.Controls.ContainsKey("pictureBox" + i.ToString()))
                {
                    PictureBox pictureBox = this.Controls["pictureBox" + i.ToString()] as PictureBox;
                    if (pictureBox != null)
                    {
                        MemoryStream ms = new MemoryStream();
                        if (pictureBox.Image != null)
                        {
                            pictureBox.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                            image = ms.GetBuffer();
                        }
                    }
                }
                if (castId != 0)
                {
                    if (character.Length > 0 && name.Length > 0 && image != null)
                    {
                        bool checkInDatabase = dbController.checkIfCastInDatabase(castId);
                        if (addOrEdit2 == 1)
                        {
                            if (checkInDatabase)
                            {
                                MessageBox.Show("Cast " + i + " with this Id is already exist");
                                error = 1;
                            }
                            else
                            {
                                dbController.insertToCast(castId, character, name, image);
                                dbController.insertCastToMovie(movieId, castId);
                            }
                        }
                        else if (addOrEdit2 == 0)
                        {
                            if (checkInDatabase)
                            {
                                dbController.updateCast(castId, character, name, image);
                            }
                            else
                            {
                                dbController.insertToCast(castId, character, name, image);
                                dbController.insertCastToMovie(movieId, castId);
                            }
                        }
                    }
                }
            }
            return(error);
        }