예제 #1
0
        // GET: Movies/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MovieNight.Models.Movie movie = db.Movies.Find(id);
            if (movie == null)
            {
                return(HttpNotFound());
            }

            // Get the current movie id from TMDB
            var currMovieID = client.SearchMovie(movie.Title).Results[0].Id;

            // Get the current movie cast from TMDB
            var currMoviecast = client.GetMovieCredits(currMovieID).Cast;

            // Set the base image URL
            string BaseImageURL = "https://image.tmdb.org/t/p/w132_and_h132_bestv2";

            // Initalize html helper with cast info
            ViewBag.Cast = currMoviecast;

            // Initalize html helper with base image url
            ViewBag.baseImageURL = BaseImageURL;

            // Initalize html helper with TMDB ID of the movie
            ViewBag.currMovieTMDBID = currMovieID;

            // Get Morew movies like this one
            ViewBag.moreLikeThis = client.GetMovieSimilar(currMovieID);

            return(View(movie));
        }
예제 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (Session["user"] == null || (Session["user"] as User).Role != Role.Admin)
            {
                return(RedirectToAction("AccessDenied", "Users"));
            }

            MovieNight.Models.Movie movie = db.Movies.Find(id);
            db.Movies.Remove(movie);
            db.SaveChanges();
            return(RedirectToAction("Manage"));
        }
예제 #3
0
        public ActionResult Edit([Bind(Include = "ID,Title,ReleaseDate,Genre,Plot,DirectorID,Rating,Poster,Trailer")] MovieNight.Models.Movie movie)
        {
            if (Session["user"] == null || (Session["user"] as User).Role != Role.Admin)
            {
                return(RedirectToAction("AccessDenied", "Users"));
            }

            if (ModelState.IsValid)
            {
                db.Entry(movie).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Manage"));
            }
            ViewBag.DirectorID = new SelectList(db.Directors, "ID", "Name", movie.DirectorID);
            return(View(movie));
        }
예제 #4
0
        public ActionResult GetNextMovies(int numOfMovies, string lastMovieTitle)
        {
            // Check the MovieNightDB state
            if (db.Database.Connection.State == ConnectionState.Open)
            {
                // Close any open DB connections
                db.Database.Connection.Close();
            }

            // Create the movie query
            var GetAllMovies = from m in db.Movies
                               select m;

            // Get the last movie displyed on page, from MovieNightDB
            MovieNight.Models.Movie lastMovie = GetAllMovies.Where(m => m.Title == lastMovieTitle).FirstOrDefault();

            // Get the next movies to return to page
            System.Collections.Generic.List <MovieNight.Models.Movie> NextMoviesToDisplay = new List <Models.Movie>();

            // Get the next movies to return to page
            NextMoviesToDisplay = GetAllMovies.Where(m => m.ID > lastMovie.ID).Take(numOfMovies).ToList();

            // Create a new movie list object
            List <MovieNight.Models.Movie> movieList = new List <Models.Movie>();

            // Create and initialize the movie object with the details of the next movie to display
            foreach (var currMovie in NextMoviesToDisplay)
            {
                // Create a new movie object
                MovieNight.Models.Movie MovieToAdd = new Models.Movie();

                // Set the new movie features
                MovieToAdd.ID          = currMovie.ID;
                MovieToAdd.Title       = currMovie.Title;
                MovieToAdd.Poster      = currMovie.Poster;
                MovieToAdd.ReleaseDate = currMovie.ReleaseDate;
                MovieToAdd.Genre       = currMovie.Genre;
                MovieToAdd.Rating      = currMovie.Rating;
                MovieToAdd.DirectorID  = currMovie.Reviews.Count();

                // Add the current movie to movies list
                movieList.Add(MovieToAdd);
            }

            // Return the wated movies to display, as JSON string
            return(this.Json(JsonConvert.SerializeObject(movieList)));
        }
예제 #5
0
        // GET: Movies/Delete/5
        public ActionResult Delete(int?id)
        {
            if (Session["user"] == null || (Session["user"] as User).Role != Role.Admin)
            {
                return(RedirectToAction("AccessDenied", "Users"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MovieNight.Models.Movie movie = db.Movies.Find(id);
            if (movie == null)
            {
                return(HttpNotFound());
            }
            return(View(movie));
        }
예제 #6
0
        // GET: Movies/Edit/5
        public ActionResult Edit(int?id)
        {
            if (Session["user"] == null || (Session["user"] as User).Role != Role.Admin)
            {
                return(RedirectToAction("AccessDenied", "Users"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MovieNight.Models.Movie movie = db.Movies.Find(id);
            if (movie == null)
            {
                return(HttpNotFound());
            }
            ViewBag.DirectorID = new SelectList(db.Directors, "ID", "Name", movie.DirectorID);
            return(View(movie));
        }
예제 #7
0
        protected override void Seed(MovieNight.Models.MovieNightDB context)
        {
            if (System.Diagnostics.Debugger.IsAttached == false)
            {
                System.Diagnostics.Debugger.Launch();
            }

            //  This method will be called after migrating to the latest version

            //var frank = new Director { Name = "Frank Darabont", DateOfBirth = DateTime.Parse("January 28, 1959"), Gender = Gender.Male, Origin = "France", Picture = "https://images-na.ssl-images-amazon.com/images/M/MV5BNjk0MTkxNzQwOF5BMl5BanBnXkFtZTcwODM5OTMwNA@@._V1_.jpg" };
            //var francis = new Director { Name = "Francis Ford Coppola", DateOfBirth = DateTime.Parse("April 7, 1939"), Gender = Gender.Male, Origin = "USA", Picture = "https://images-na.ssl-images-amazon.com/images/M/MV5BMTM5NDU3OTgyNV5BMl5BanBnXkFtZTcwMzQxODA0NA@@._V1_SY1000_CR0,0,665,1000_AL_.jpg" };
            //var christ = new Director { Name = "Christopher Nolan", DateOfBirth = DateTime.Parse("July 30, 1970"), Gender = Gender.Male, Origin = "UK", Picture = "https://images-na.ssl-images-amazon.com/images/M/MV5BNjE3NDQyOTYyMV5BMl5BanBnXkFtZTcwODcyODU2Mw@@._V1_.jpg" };

            //var directors = new List<Director>
            //{
            //    frank, francis, christ
            //};

//            directors.ForEach(s => context.Directors.AddOrUpdate(s));
//          context.SaveChanges();

            //var shawshank = new MovieNight.Models.Movie { Title = "The Shawshank Redemption", Genre = "Crime, Drama", Director = frank, Plot = "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.", Poster = "https://images-na.ssl-images-amazon.com/images/M/MV5BODU4MjU4NjIwNl5BMl5BanBnXkFtZTgwMDU2MjEyMDE@._V1_SY1000_CR0,0,672,1000_AL_.jpg", Rating = 9.3, ReleaseDate = DateTime.Parse("September 23, 1994") };
            //var godfather = new MovieNight.Models.Movie { Title = "The Godfather", Genre = "Crime, Drama", Director = francis, Plot = "The aging patriarch of an organized crime dynasty transfers control of his clandestine empire to his reluctant son.", Poster = "https://images-na.ssl-images-amazon.com/images/M/MV5BMmE4MjdiZjctMjU3Ni00ZTM5LWIxNGMtNjgzZjQ2Y2Y3ZTliXkEyXkFqcGdeQXVyMjUzOTY1NTc@._V1_UX182_CR0,0,182,268_AL_.jpg", Rating = 9.2, ReleaseDate = DateTime.Parse("March 15, 1972") };
            //var godfather2 = new MovieNight.Models.Movie { Title = "The Godfather: Part II", Genre = "Crime, Drama", Director = francis, Plot = "The early life and career of Vito Corleone in 1920s New York is portrayed while his son, Michael, expands and tightens his grip on his crime syndicate stretching from Lake Tahoe, Nevada to pre-revolution 1958 Cuba.", Poster = "https://images-na.ssl-images-amazon.com/images/M/MV5BNDVjZjgxNTgtMGNhMC00YWU0LTg0YTQtNTkxNzBjMDBkNWYyXkEyXkFqcGdeQXVyNTA4NzY1MzY@._V1_UY268_CR3,0,182,268_AL_.jpg", Rating = 9.0, ReleaseDate = DateTime.Parse("December 12, 1974") };
            //var batman = new MovieNight.Models.Movie { Title = "The Dark Knight", Genre = "Action, Crime, Drama", Director = christ, Plot = "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, the caped crusader must come to terms with one of the greatest psychological tests of his ability to fight injustice.", Poster = "https://images-na.ssl-images-amazon.com/images/M/MV5BMTMxNTMwODM0NF5BMl5BanBnXkFtZTcwODAyMTk2Mw@@._V1_UX182_CR0,0,182,268_AL_.jpg", Rating = 9.0, ReleaseDate = DateTime.Parse("July 24, 2008") };

            //var movies = new List<MovieNight.Models.Movie>
            //{
            //    shawshank,
            //    godfather,
            //    godfather2,
            //    batman
            //};

//            movies.ForEach(s => context.Movies.AddOrUpdate(p => p.Title, s));
//          context.SaveChanges();

//            var rev1 = new Review { Movie = batman, Content = "Awsome movie, realy loved it", CriticName = "Eylam Milner", Date = DateTime.Now };
//            var rev2 = new Review { Movie = godfather, Content = "Awsome movie, realy loved it", CriticName = "Eylam Milner", Date = DateTime.Now };
//            var rev3 = new Review { Movie = batman, Content = "Great movie, I realy enjoyed it", CriticName = "Lucas Aides", Date = DateTime.Now };

//            var reviews = new List<Review>
//            {
//                rev1,rev2,rev3
//            };

//            reviews.ForEach(s => context.Reviews.AddOrUpdate(p => p.ID, s));
//            context.SaveChanges();

            var user = new User {
                Username = "******", Password = "******", Role = Role.SimpleUser
            };
            var admin = new User {
                Username = "******", Password = "******", Role = Role.Admin
            };

            context.Users.AddOrUpdate(p => p.ID, user);
            context.Users.AddOrUpdate(p => p.ID, admin);
            context.SaveChanges();

            // TMDB API
            // TMDB API
            // TMDB API
            // TMDB API

            // Connectiong to TMDB API
            TMDbClient client = new TMDbClient("e77a93ac7dab813a39327cfaa10938e8");

            // Get the top rated movies
            TMDbLib.Objects.General.SearchContainer <TMDbLib.Objects.General.MovieResult> TopRatedMovies = client.GetMovieList(MovieListType.TopRated);

            // Get the now playing movies
            TMDbLib.Objects.General.SearchContainer <TMDbLib.Objects.General.MovieResult> NowPlayingMovies = client.GetMovieList(MovieListType.NowPlaying);

            // Get the popular movies
            TMDbLib.Objects.General.SearchContainer <TMDbLib.Objects.General.MovieResult> PopularMovies = client.GetMovieList(MovieListType.Popular);

            // Get the upcoming movies
            TMDbLib.Objects.General.SearchContainer <TMDbLib.Objects.General.MovieResult> UpComingMovies = client.GetMovieList(MovieListType.Upcoming);

            string BaseImgURL = "https://image.tmdb.org/t/p/w300";

            var Addedmovies = new List <MovieNight.Models.Movie>();

            // Goes over all of the now playing movies
            foreach (MovieResult currMovie in NowPlayingMovies.Results)
            {
                // Get the genre list into one string
                List <Genre> genreList = client.GetMovie(currMovie.Id).Genres;

                // The new string value for the genre list
                string currMoviegenre = "";

                // Goes over all of the genres and add them to the new string
                foreach (Genre cuurGenre in genreList)
                {
                    // Add the current genre to new genre string
                    currMoviegenre += cuurGenre.Name + ", ";
                }

                // Trim trailing comma and white space
                currMoviegenre = currMoviegenre.TrimEnd(' ').TrimEnd(',');

                // Set movie trailer base path
                string MovieTralierBasePath = "https://www.youtube.com/embed/";

                string currMovieTrailerPath = "";

                if (client.GetMovie(currMovie.Id, MovieMethods.Videos).Videos.Results.Count() != 0)
                {
                    // Get the current movie video path
                    currMovieTrailerPath = client.GetMovie(currMovie.Id, MovieMethods.Videos).Videos.Results[0].Key;
                }

                // Get the current movie's director ID
                TMDbLib.Objects.General.Crew currdirector = client.GetMovieCredits(currMovie.Id).Crew.Where(crew1 => crew1.Job == "Director").ElementAt(0);

                // Get the current director object
                TMDbLib.Objects.People.Person director = client.GetPerson(currdirector.Id);

                // Create the current movie director object
                Director NewDirector = new Director
                {
                    Name        = director.Name,
                    Gender      = Gender.Male,
                    DateOfBirth = (director.Birthday == null ? DateTime.Parse("January 1, 1900") : (DateTime)director.Birthday.Value.Date),
                    Origin      = (director.PlaceOfBirth == null ? "Unknown" : director.PlaceOfBirth.Split(',').Last()),
                    Picture     = BaseImgURL + director.ProfilePath
                };

                // Adds the new director to directors DB
                context.Directors.Add(NewDirector);
//              context.SaveChanges();

                // Create the new movie object
                var NewMovie = new MovieNight.Models.Movie
                {
                    Title       = currMovie.Title,
                    Genre       = currMoviegenre,
                    Director    = NewDirector,
                    Plot        = currMovie.Overview,
                    Poster      = BaseImgURL + currMovie.PosterPath,
                    Rating      = currMovie.VoteAverage,
                    ReleaseDate = currMovie.ReleaseDate.Value.Date,
                    Trailer     = MovieTralierBasePath + currMovieTrailerPath
                };

                // Adds the new movie to movies DB
                context.Movies.Add(NewMovie);
                context.SaveChanges();
            }
            // TMDB API
            // TMDB API
            // TMDB API
            // TMDB API
        }
예제 #8
0
        protected override void Seed(MovieNight.Models.MovieNightDB context)
        {
            if (System.Diagnostics.Debugger.IsAttached == false)
            {
                System.Diagnostics.Debugger.Launch();
            }

            var user = new User {
                Username = "******", Password = "******", Role = Role.SimpleUser
            };
            var admin = new User {
                Username = "******", Password = "******", Role = Role.Admin
            };

            context.Users.AddOrUpdate(p => p.ID, user);
            context.Users.AddOrUpdate(p => p.ID, admin);
            context.SaveChanges();

            // TMDB API
            // TMDB API
            // TMDB API
            // TMDB API

            // Connectiong to TMDB API
            TMDbClient client = new TMDbClient("e77a93ac7dab813a39327cfaa10938e8");

            // Get the top rated movies
            TMDbLib.Objects.General.SearchContainer <TMDbLib.Objects.General.MovieResult> TopRatedMovies = client.GetMovieList(MovieListType.TopRated);

            // Get the now playing movies
            TMDbLib.Objects.General.SearchContainer <TMDbLib.Objects.General.MovieResult> NowPlayingMovies = client.GetMovieList(MovieListType.NowPlaying);

            // Get the popular movies
            TMDbLib.Objects.General.SearchContainer <TMDbLib.Objects.General.MovieResult> PopularMovies = client.GetMovieList(MovieListType.Popular);

            // Get the upcoming movies
            TMDbLib.Objects.General.SearchContainer <TMDbLib.Objects.General.MovieResult> UpComingMovies = client.GetMovieList(MovieListType.Upcoming);

            string BaseImgURL = "https://image.tmdb.org/t/p/w300";

            var Addedmovies = new List <MovieNight.Models.Movie>();

            // Goes over all of the now playing movies
            foreach (MovieResult currMovie in NowPlayingMovies.Results)
            {
                // Get the genre list into one string
                List <Genre> genreList = client.GetMovie(currMovie.Id).Genres;

                // The new string value for the genre list
                string currMoviegenre = "";

                // Goes over all of the genres and add them to the new string
                foreach (Genre cuurGenre in genreList)
                {
                    // Add the current genre to new genre string
                    currMoviegenre += cuurGenre.Name + ", ";
                }

                // Trim trailing comma and white space
                currMoviegenre = currMoviegenre.TrimEnd(' ').TrimEnd(',');

                // Set movie trailer base path
                string MovieTralierBasePath = "https://www.youtube.com/embed/";

                string currMovieTrailerPath = "";

                if (client.GetMovie(currMovie.Id, MovieMethods.Videos).Videos.Results.Count() != 0)
                {
                    // Get the current movie video path
                    currMovieTrailerPath = client.GetMovie(currMovie.Id, MovieMethods.Videos).Videos.Results[0].Key;
                }

                // Get the current movie's director ID
                TMDbLib.Objects.General.Crew currdirector = client.GetMovieCredits(currMovie.Id).Crew.Where(crew1 => crew1.Job == "Director").ElementAt(0);

                // Get the current director object
                TMDbLib.Objects.People.Person director = client.GetPerson(currdirector.Id);

                // Create the current movie director object
                Director NewDirector = new Director
                {
                    Name        = director.Name,
                    Gender      = Gender.Male,
                    DateOfBirth = (director.Birthday == null ? DateTime.Parse("January 1, 1900") : (DateTime)director.Birthday.Value.Date),
                    Origin      = (director.PlaceOfBirth == null ? "Unknown" : director.PlaceOfBirth.Split(',').Last()),
                    Picture     = BaseImgURL + director.ProfilePath
                };

                // Adds the new director to directors DB
                context.Directors.Add(NewDirector);
//              context.SaveChanges();

                // Create the new movie object
                var NewMovie = new MovieNight.Models.Movie
                {
                    Title       = currMovie.Title,
                    Genre       = currMoviegenre,
                    Director    = NewDirector,
                    Plot        = currMovie.Overview,
                    Poster      = BaseImgURL + currMovie.PosterPath,
                    Rating      = currMovie.VoteAverage,
                    ReleaseDate = currMovie.ReleaseDate.Value.Date,
                    Trailer     = MovieTralierBasePath + currMovieTrailerPath
                };

                // Adds the new movie to movies DB
                context.Movies.Add(NewMovie);
                context.SaveChanges();
            }
            // TMDB API
            // TMDB API
            // TMDB API
            // TMDB API
        }