Beispiel #1
0
        public static bool AddMovie(Movie movie)
        {
            bool result = false;

            if (MovieValidation.IsValidMovieInput(movie))
            {
                Query.queryToExecute = string.Format(
                    "INSERT INTO movies (name, description, genre, year, duration, actors, director, poster, trailer_url) " +
                    "VALUES (\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\", \"{5}\", \"{6}\", \"{7}\", \"{8}\");",
                    movie.Name, movie.Description, movie.Genre, movie.Year, movie.Duration, movie.Actors, movie.Director, movie.Poster, movie.TrailerUrl);

                int queryResult = Query.queryExecutor.ExecuteNonQuery(Query.queryToExecute);

                if (queryResult == 1)
                {
                    result = true;
                }
                else
                {
                    MessageBox.Show("Error while adding the movie!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            return result;
        }
        public static bool IsValidMovieInput(Movie movie)
        {
            bool result = true;

            if (!IsValidName(movie.Name))
            {
                result = false;
            }

            if (!IsValidDescription(movie.Description))
            {
                result = false;
            }

            if (!IsValidGenre(movie.Genre))
            {
                result = false;
            }

            if (!IsValidActors(movie.Actors))
            {
                result = false;
            }

            if (!IsValidDirector(movie.Director))
            {
                result = false;
            }

            if (!IsValidPoster(movie.Poster))
            {
                result = false;
            }

            if (!IsValidTrailer(movie.TrailerUrl))
            {
                result = false;
            }

            if (!IsValidYear(movie.Year))
            {
                result = false;
            }

            if (!IsValidDuration(movie.Duration))
            {
                result = false;
            }

            return result;
        }
Beispiel #3
0
        private void btnAddMovie_Click(object sender, RoutedEventArgs e)
        {
            if (!this.isUploaded)
            {
                MessageBox.Show("First, you must upload the image!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                int year = 0;

                if (!int.TryParse(this.txtYear.Text, out year))
                {
                    MessageBox.Show("Your input for year is not a number!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                int duration = 0;

                if (!int.TryParse(this.txtDuration.Text, out duration))
                {
                    MessageBox.Show("Your input for duration is not a number!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                Movie movie = new Movie(this.txtName.Text, this.txtDescription.Text, this.txtGenre.Text, year,
                    duration, this.txtActors.Text, this.txtDirector.Text, this.poster, this.txtTrailer.Text);

                if (AdminQuery.AddMovie(movie))
                {
                    MessageBox.Show("Movie was added successfully", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                    MainWindow mainWindow = StartWindow.GetMainWindow(this);
                    mainWindow.movies.moviesContainer.Children.Clear();
                    mainWindow.movies.LoadMovies();
                    mainWindow.movies.InsertAddButton();

                    mainWindow.movieInformation.FillInformation(movie.Name);
                    this.Visibility = Visibility.Hidden;
                    mainWindow.movieInformation.Visibility = Visibility.Visible;
                    this.ClearFields();
                }
            }
        }
Beispiel #4
0
        public static List<Movie> GetMovies()
        {
            List<Movie> currentMovies = new List<Movie>();

            queryToExecute = "SELECT * FROM movies;";
            MySqlDataReader reader = queryExecutor.ExecuteQuery(queryToExecute);

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    Movie movie = new Movie(
                        reader.GetInt32(0),
                        reader.GetString(1),
                        reader.GetString(2),
                        reader.GetString(3),
                        reader.GetInt32(4),
                        reader.GetInt32(5),
                        reader.GetString(6),
                        reader.GetString(7),
                        reader.GetString(8),
                        reader.GetString(9),
                        reader.GetFloat(10)
                        );

                    currentMovies.Add(movie);
                }
            }

            reader.Close();
            return currentMovies;
        }
Beispiel #5
0
        public static Movie GetMovieInfo(string name)
        {
            Movie movie = null;

            queryToExecute = string.Format("SELECT movies.id, movies.name, movies.description, " +
            "movies.genre, movies.year, movies.duration, movies.actors, movies.director, " +
            "movies.poster, movies.trailer_url, movies.rating, COUNT(comments.id)" +
            "FROM movies LEFT JOIN comments ON movies.id = comments.movie_id WHERE name = \"{0}\";", name);

            MySqlDataReader reader = queryExecutor.ExecuteQuery(queryToExecute);

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    movie = new Movie(
                        reader.GetInt32(0),
                        reader.GetString(1),
                        reader.GetString(2),
                        reader.GetString(3),
                        reader.GetInt32(4),
                        reader.GetInt32(5),
                        reader.GetString(6),
                        reader.GetString(7),
                        reader.GetString(8),
                        reader.GetString(9),
                        reader.GetFloat(10),
                        reader.GetInt32(11)
                        );
                }
            }

            reader.Close();
            return movie;
        }