Exemple #1
0
 protected void UpdateMovie(object sender, EventArgs e)
 {
     DbMovie movie = new DbMovie(MovieTitle.Text, Convert.ToInt32(ReleaseDate.Text), Convert.ToInt32(Duration.Text), Rating.Text);
     movie.Id = MovieId;
     DbMovie.UpdateMovie(Connection, movie);
     Response.Redirect("Browse.aspx");
 }
Exemple #2
0
 protected void InsertMovie(object sender, EventArgs e)
 {
     Connection.Open();
     DbMovie movie = new DbMovie(MovieTitle.Text, Convert.ToInt32(ReleaseDate.Text), Convert.ToInt32(Duration.Text), Rating.Text);
     SqlCommand cmd = movie.Insert(Connection);
     cmd.ExecuteScalar();
     Connection.Close();
     Response.Redirect("Browse.aspx");
 }
Exemple #3
0
 public static void UpdateMovie(SqlConnection conn, DbMovie movie)
 {
     conn.Open();
     movie.Title = movie.Title.Replace("'", "''");
     string update = string.Format("UPDATE {0} SET title='{1}', release_year={2}, duration={3}, rating='{4}' WHERE id={5}",
         TableName, movie.Title, movie.ReleaseYear, movie.Duration, movie.Rating, movie.Id);
     SqlCommand cmd = new SqlCommand(update, conn);
     cmd.ExecuteScalar();
     conn.Close();
 }
Exemple #4
0
 public static List<DbMovie> GetSimilarMovies(SqlConnection conn, long genreId)
 {
     conn.Open();
     SqlCommand cmd = new SqlCommand("getSimilarMovies", conn);
     cmd.Parameters.AddWithValue("@GenreId", genreId);
     cmd.CommandType = CommandType.StoredProcedure;
     SqlDataReader reader = cmd.ExecuteReader();
     List<DbMovie> movies = new List<DbMovie>();
     while (reader.Read())
     {
         DbMovie movie = new DbMovie();
         movie.Id = reader.GetInt32(1);
         movie.Title = reader.GetString(2) as string;
         movie.ReleaseYear = reader.GetInt32(3);
         movie.Duration = reader.GetInt32(4);
         movie.Rating = reader.GetString(5) as string;
         movie.UserRating = (float)reader.GetDouble(6);
         movie.UserRatingCount = reader.GetInt32(7);
         movie.Overview = reader.GetString(8) as string;
         movie.PosterImageUrl = reader.GetString(9) as string;
         if (!movies.Contains(movie))
             movies.Add(movie);
     }
     conn.Close();
     return movies;
 }
Exemple #5
0
 public static DbMovie GetMovie(SqlConnection conn, string title)
 {
     conn.Open();
     title = title.Replace("'", "''");
     SqlCommand cmd = new SqlCommand(string.Format("SELECT * FROM {0} WHERE title='{1}'", TableName, Uri.UnescapeDataString(title)), conn);
     SqlDataReader reader = cmd.ExecuteReader();
     DbMovie movie = new DbMovie();
     while (reader.Read())
     {
         movie.Id = reader.GetInt32(0);
         movie.Title = reader.GetString(1) as string;
         movie.ReleaseYear = reader.GetInt32(2);
         movie.Duration = reader.GetInt32(3);
         movie.Rating = reader.GetString(4) as string;
         movie.UserRating = (float)reader.GetDouble(5);
         movie.UserRatingCount = reader.GetInt32(6);
         movie.Overview = reader.GetString(7) as string;
         movie.PosterImageUrl = reader.GetString(8) as string;
     }
     conn.Close();
     return movie;
 }
Exemple #6
0
        public static void ProcessMovieResponse(List<Movie> movies, SqlConnection connection)
        {
            connection.Open();
            DataTable data = new DataTable();
            int movieCount = 0;
            foreach (Movie movie in movies)
            {
                try
                {
                    DbMovie dbMovie = new DbMovie()
                    {
                        Title = movie.Title
                    };
                    var rating = (from r in movie.Releases.Results
                                  where r.CountryCode.Contains("US")
                                  select r).FirstOrDefault();
                    dbMovie.Rating = rating != null ? rating.Certification : "";
                    if (movie.ReleaseDate.HasValue)
                        dbMovie.ReleaseYear = movie.ReleaseDate.Value.Year;
                    if (movie.Runtime.HasValue)
                        dbMovie.Duration = movie.Runtime.Value;
                    dbMovie.UserRating = (float)movie.VoteAverage;
                    dbMovie.UserRatingCount = movie.VoteCount;
                    dbMovie.Overview = movie.Overview;
                    dbMovie.PosterImageUrl = DbEntity.GetImageUrl(movie.Poster);
                    var mRes = dbMovie.Insert(connection).ExecuteReader();
                    data.Load(mRes);
                    mRes.Close();
                    //int movieId = (int)dbMovie.Insert(connection).ExecuteScalar();
                    int movieId = (int)data.Select().FirstOrDefault()["Id"];
                    var res = data.Select().FirstOrDefault()["Response"];
                    if (res != null)
                        Console.WriteLine(res);
                    else
                        Console.WriteLine(string.Format("Movie ({0}) inserted...", movie.Title));
                    data.Clear();

                    var directorQuery = from d in movie.Credits.Crew
                                        where d.Department.Contains("Directing")
                                        where d.Job.Contains("Director")
                                        select d;
                    if (directorQuery.FirstOrDefault() != null)
                    {
                        DbDirector director = new DbDirector(directorQuery.FirstOrDefault().Name, DbEntity.GetImageUrl(directorQuery.FirstOrDefault().Profile));
                        var dRes = director.Insert(connection).ExecuteReader();
                        data.Load(dRes);
                        dRes.Close();
                        int directorId = (int)data.Select().FirstOrDefault()["Id"];
                        res = data.Select().FirstOrDefault()["Response"];
                        if (res != null)
                            Console.WriteLine(res);
                        //else
                        //    Console.WriteLine(string.Format("Director ({0}) inserted...", director.Name));
                        data.Clear();

                        DbDirectMovie directMovie = new DbDirectMovie(directorId, movieId);
                        directMovie.Insert(connection).ExecuteNonQuery();
                        //Console.WriteLine(string.Format("Movie ({0}) linked with Director ({1})...", dbMovie.Title, director.Name));
                    }

                    foreach (MediaCast actor in movie.Credits.Cast)
                    {
                        string name = actor.Name;
                        if (name.Contains("'"))
                        {
                            name = name.Replace("'", "''");
                        }
                        DbActor dbActor = new DbActor(name, DbEntity.GetImageUrl(actor.Profile));
                        var aRes = dbActor.Insert(connection).ExecuteReader();
                        data.Load(aRes);
                        aRes.Close();
                        int actorId = (int)data.Select().FirstOrDefault()["Id"];
                        res = data.Select().FirstOrDefault()["Response"];
                        if (res != null)
                            Console.WriteLine(res);
                        //else
                        //    Console.WriteLine(string.Format("Actor ({0}) inserted...", dbActor.Name));
                        data.Clear();

                        string roleName = actor.Character;
                        if (roleName.Contains("'"))
                        {
                            roleName = roleName.Replace("'", "''");
                        }
                        DbActorRole actorRole = new DbActorRole(actorId, movieId, roleName);
                        actorRole.Insert(connection).ExecuteNonQuery();
                        //Console.WriteLine(string.Format("Actor ({0}) with Role ({1}) linked with Movie ({2})...", dbActor.Name, actorRole.ActorRole, dbMovie.Title));
                    }

                    foreach (Genre genre in movie.Genres)
                    {
                        DbGenre dbGenre = new DbGenre(genre.Name);
                        var gRes = dbGenre.Insert(connection).ExecuteReader();
                        data.Load(gRes);
                        gRes.Close();
                        int genreId = (int)data.Select().FirstOrDefault()["Id"];
                        res = data.Select().FirstOrDefault()["Response"];
                        if (res != null)
                            Console.WriteLine(res);
                        //else
                        //    Console.WriteLine(string.Format("Genre ({0}) inserted...", dbGenre.Genre));
                        data.Clear();

                        DbMovieGenre movieGenre = new DbMovieGenre(genreId, movieId);
                        movieGenre.Insert(connection).ExecuteNonQuery();
                        //Console.WriteLine(string.Format("Genre ({0}) linked with Movie ({1})...", dbGenre.Genre, dbMovie.Title));
                    }

                    foreach (Image image in movie.Images.Backdrops)
                    {
                        DbBackdrop dbBackdrop = new DbBackdrop();
                        dbBackdrop.BackdropUrl = GetImageUrl(image.FilePath);
                        var bRes = dbBackdrop.Insert(connection).ExecuteReader();
                        data.Load(bRes);
                        bRes.Close();
                        int backdropId = (int)data.Select().FirstOrDefault()["Id"];
                        res = data.Select().FirstOrDefault()["Response"];
                        if (res != null)
                            Console.WriteLine(res);
                        //else
                        //    Console.WriteLine(string.Format("Backdrop image ({0}) inserted...", dbBackdrop.BackdropUrl));
                        data.Clear();

                        DbMovieBackdrop dbMovieBackdrop = new DbMovieBackdrop();
                        dbMovieBackdrop.MovieId = movieId;
                        dbMovieBackdrop.BackdropId = backdropId;
                        dbMovieBackdrop.Insert(connection).ExecuteNonQuery();
                        //Console.WriteLine(string.Format("Backdrop Image ({0}) linked with Movie ({1})...", dbMovieBackdrop.BackdropId, dbMovieBackdrop.MovieId));
                    }
                    movieCount++;
                    Console.WriteLine(string.Format("Finished processing movie #{0} out of #{1}", movieCount, movies.Count));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            }
            connection.Close();
        }