Esempio n. 1
0
        /// <summary>
        /// Assigns an Language to a Movie in the database.
        /// Adds the Language to the database if it does not exist.
        /// Returns true if successful; false otherwise.
        /// </summary>
        /// <param name="movieLanguageName"></param>
        /// <returns></returns>
        public bool AddMovieLanguage(string movieId, string movieLanguageName)
        {
            if (!MovieExists(movieId))
            {
                return(false);
            }
            if (!LanguageExists(movieLanguageName))
            {
                Language newLanguage = new Language();
                newLanguage.LanguageName = movieLanguageName;
                AddLanguage(newLanguage);
            }

            Language language = GetLanguage(movieLanguageName);

            if (language == null)
            {
                return(false);
            }

            MovieLanguage movieLanguage = new MovieLanguage();

            movieLanguage.ImdbId     = movieId;
            movieLanguage.LanguageId = language.LanguageId;
            _dbContext.MovieLanguages.Add(movieLanguage);
            _dbContext.SaveChanges();
            return(true);
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(long id, [Bind("MovieId,LanguageIsoCode")] MovieLanguage movieLanguage)
        {
            if (id != movieLanguage.MovieId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(movieLanguage);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieLanguageExists(movieLanguage.MovieId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LanguageIsoCode"] = new SelectList(_context.Language, "LanguageIsoCode", "LanguageIsoCode", movieLanguage.LanguageIsoCode);
            ViewData["MovieId"]         = new SelectList(_context.Movie, "Id", "Description", movieLanguage.MovieId);
            return(View(movieLanguage));
        }
Esempio n. 3
0
        /// <summary>Gets the language by id.</summary>
        /// <param name="id">The language id.</param>
        /// <returns>The movie language.</returns>
        public MovieLanguage GetLanguageById(int id)
        {
            this.Logger.Debug("Getting movie language with the id: " + id);

            MovieLanguage language = this.Session.Get <MovieLanguage>(id);

            this.Logger.Debug("Got the movie language: " + language);

            return(language);
        }
Esempio n. 4
0
 public Movie(string newMovieName, int newLengthInMin, string newSummary, DateTime newYear, MovieGenre newGenre, RatingType newContentRating, MovieLanguage newLanguage)
 {
     MovieName     = newMovieName;
     LengthInMin   = newLengthInMin;
     Summary       = newSummary;
     Year          = newYear;
     Genre         = newGenre;
     ContentRating = newContentRating;
     Language      = newLanguage;
 }
Esempio n. 5
0
        public ActionResult Create()
        {
            var viewModel = new MovieFormViewModel
            {
                types     = MovieType.getTypes(),
                languages = MovieLanguage.getLanguages(),
                Watched   = MovieWatched.getWatched()
            };

            return(View(viewModel));
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([Bind("MovieId,LanguageIsoCode")] MovieLanguage movieLanguage)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movieLanguage);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LanguageIsoCode"] = new SelectList(_context.Language, "LanguageIsoCode", "LanguageIsoCode", movieLanguage.LanguageIsoCode);
            ViewData["MovieId"]         = new SelectList(_context.Movie, "Id", "Description", movieLanguage.MovieId);
            return(View(movieLanguage));
        }
Esempio n. 7
0
        public ActionResult Edit(int id)
        {
            IQueryable <Movie> movies = Movie.getMovies().AsQueryable();
            Movie movie = movies.FirstOrDefault(m => m.id == id);

            var viewModel = new MovieFormViewModel
            {
                movie     = movie,
                types     = MovieType.getTypes(),
                languages = MovieLanguage.getLanguages(),
                Watched   = MovieWatched.getWatched()
            };

            return(View("Create", viewModel));
        }
Esempio n. 8
0
        public async Task <IActionResult> AddLanguage(long movieId, int languageId)
        {
            var language = await db.Languages
                           .Where(x => x.Id == languageId)
                           .SingleOrDefaultAsync();

            if (language == null)
            {
                return(NotFound(new ResWrapper {
                    args = new { movieId, languageId }, Status = "NotFound:Language"
                }));
            }

            var movie = await db.Movies
                        .Where(x => x.Id == movieId)
                        .SingleOrDefaultAsync();

            if (movie == null)
            {
                return(NotFound(new ResWrapper {
                    args = new { movieId, languageId }, Status = "NotFound:Movie"
                }));
            }

            var movieLanguage = await db.MovieLanguages
                                .Where(x => x.MovieId == movieId && x.LanguageId == languageId)
                                .SingleOrDefaultAsync();

            if (movieLanguage != null)
            {
                return(Ok(new ResWrapper {
                    args = new { movieId, languageId }, Status = "OK", Data = new { movie, language }
                }));
            }

            movieLanguage = new MovieLanguage {
                Movie = movie, Language = language, LanguageId = languageId, MovieId = movieId
            };
            await db.AddAsync(movieLanguage);

            await db.SaveChangesAsync();

            return(Ok(new ResWrapper {
                args = new { movieId, languageId }, Status = "OK", Data = new { movie, language }
            }));
        }
Esempio n. 9
0
        public IActionResult AddMovie(AddMovie addMovieModel)
        {
            using (var txn = _session.BeginTransaction())
            {
                string        MovieName     = addMovieModel.MovieName;
                int           LengthInMin   = addMovieModel.LengthInMin;
                string        Summary       = addMovieModel.Summary;
                DateTime      Year          = addMovieModel.Year;
                MovieGenre    Genre         = addMovieModel.Genre;
                RatingType    ContentRating = addMovieModel.ContentRating;
                MovieLanguage Language      = addMovieModel.Language;

                Movie newMovie = new Movie(MovieName, LengthInMin, Summary, Year, Genre, ContentRating, Language);
                _session.Save(newMovie);
                txn.Commit();
            }

            //Movie newMovie = new Movie(MovieName, LengthInMin, Summary, Year, Genre, ContentRatingEnum);
            // session.Save(newMovie);
            return(RedirectToAction("Index"));
        }
        public Movie CollectAndAddMovieToDb(Movie movie2, string moviePage = null, bool collectKeyword = true)
        {
            if (string.IsNullOrEmpty(moviePage))
            {
                InvokeOnNotificationFired("Started collecting movie: " + movie2.Title);
                moviePage = HttpHelper.FetchWebPage(ImdbTitle + movie2.ImdbId);
            }

            var parseMovieInfo = ParseMovieInfo(moviePage);

            if (parseMovieInfo == null)
            {
                return(null);
            }



            var movie = _entities.Movies.Where(o => o.ImdbId == parseMovieInfo.ImdbId).FirstOrDefault();

            if (movie == null)
            {
                movie           = parseMovieInfo;
                movie.IsUpdated = false;
                _entities.AddToMovies(movie);
                _entities.SaveChanges();
            }
            else
            {
                movie.CopyFromMovie(parseMovieInfo);
                _entities.SaveChanges();
            }

            foreach (var g in parseMovieInfo.Genres)
            {
                var genre      = GetGenre(g);
                var movieGenre = _entities.MovieGenres.Where(o => o.Movie.Id == movie.Id && o.Genre.Id == genre.Id).FirstOrDefault();

                if (movieGenre != null)
                {
                    continue;
                }
                movieGenre = new MovieGenre {
                    Movie = movie, Genre = genre
                };
                _entities.AddToMovieGenres(movieGenre);
                _entities.SaveChanges();
            }

            foreach (var g in parseMovieInfo.Languages)
            {
                var language      = GetLanguage(g);
                var movieLanguage = _entities.MovieLanguages.Where(o => o.Movie.Id == movie.Id && o.Language.Id == language.Id).FirstOrDefault();

                if (movieLanguage != null)
                {
                    continue;
                }
                movieLanguage = new MovieLanguage {
                    Movie = movie, Language = language
                };
                _entities.AddToMovieLanguages(movieLanguage);
                _entities.SaveChanges();
            }

            foreach (var g in parseMovieInfo.Countries)
            {
                var country      = GetCountry(g);
                var movieCountry = _entities.MovieCountries.Where(o => o.Movie.Id == movie.Id && o.Country.Id == country.Id).FirstOrDefault();

                if (movieCountry != null)
                {
                    continue;
                }
                movieCountry = new MovieCountry {
                    Movie = movie, Country = country
                };
                _entities.AddToMovieCountries(movieCountry);
                _entities.SaveChanges();
            }

            foreach (var g in parseMovieInfo.PersonDirectors)
            {
                var person   = GetPerson(g);
                var director = _entities.Directors.Where(o => o.Movie.Id == movie.Id && o.Person.Id == person.Id).FirstOrDefault();

                if (director != null)
                {
                    continue;
                }
                director = new Director {
                    Movie = movie, Person = person
                };
                _entities.AddToDirectors(director);
                _entities.SaveChanges();
            }

            foreach (var g in parseMovieInfo.PersonStars)
            {
                var person = GetPerson(g);
                var star   = _entities.Stars.Where(o => o.Movie.Id == movie.Id && o.Person.Id == person.Id).FirstOrDefault();

                if (star != null)
                {
                    continue;
                }
                star = new Star {
                    Movie = movie, Person = person
                };
                _entities.AddToStars(star);
                _entities.SaveChanges();
            }

            foreach (var g in parseMovieInfo.PersonWriters)
            {
                var person = GetPerson(g);
                var writer = _entities.Writers.Where(o => o.Movie.Id == movie.Id && o.Person.Id == person.Id).FirstOrDefault();

                if (writer != null)
                {
                    continue;
                }
                writer = new Writer {
                    Movie = movie, Person = person
                };
                _entities.AddToWriters(writer);
                _entities.SaveChanges();
            }


            if (collectKeyword)
            {
                var keywordPage = HttpHelper.FetchWebPage(string.Format(ImdbKeywordUrl, parseMovieInfo.ImdbId));
                parseMovieInfo.Keywords = ImdbParser.ParseKeywords(keywordPage);

                foreach (var g in parseMovieInfo.Keywords)
                {
                    var keyword      = GetKeyword(g);
                    var movieKeyword =
                        _entities.MovieKeywords.Where(o => o.Movie.Id == movie.Id && o.Keyword.Id == keyword.Id).
                        FirstOrDefault();

                    if (movieKeyword != null)
                    {
                        continue;
                    }
                    movieKeyword = new MovieKeyword {
                        Movie = movie, Keyword = keyword
                    };
                    _entities.AddToMovieKeywords(movieKeyword);
                    _entities.SaveChanges();
                }
            }
            InvokeOnNotificationFired("Fiished collecting movie: " + movie.Title);

            movie.IsUpdated = true;
            _entities.SaveChanges();

            return(movie);
        }
        /// <summary>
        /// Adds the provided Movie and all associated information (Actors, Directors, Genres,
        /// Languages, Tags) to the provided context. Assumes the all Movie information is
        /// unique, GetRandomMovie() provides a Movie with information that is astronomically
        /// unlikely to repeat.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="movieDTO"></param>
        public static void AddMovieDTOToDatabase(Cinephiliacs_MovieContext context, MovieDTO movieDTO)
        {
            Movie movie = new Movie();

            movie.ImdbId = movieDTO.ImdbId;
            movie.Title  = movieDTO.Title;

            Rating newRating = new Rating();

            newRating.RatingName = movieDTO.RatingName;
            context.Ratings.Add(newRating);
            context.SaveChanges();
            movie.RatingId = context.Ratings.FirstOrDefault(r => r.RatingName == movieDTO.RatingName).RatingId;

            movie.ReleaseDate    = DateTime.ParseExact(movieDTO.ReleaseDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);
            movie.IsReleased     = true;
            movie.ReleaseCountry = movieDTO.ReleaseCountry;
            movie.RuntimeMinutes = movieDTO.RuntimeMinutes;
            movie.Plot           = movieDTO.Plot;
            movie.PosterUrl      = movieDTO.PosterURL;

            context.Movies.Add(movie);
            context.SaveChanges();

            foreach (var movieActorName in movieDTO.MovieActors)
            {
                Actor newActor = new Actor();
                newActor.ActorName = movieActorName;
                context.Actors.Add(newActor);
                context.SaveChanges();

                Actor actor = context.Actors.FirstOrDefault(a => a.ActorName == movieActorName);

                MovieActor movieActor = new MovieActor();
                movieActor.ImdbId  = movieDTO.ImdbId;
                movieActor.ActorId = actor.ActorId;
                context.MovieActors.Add(movieActor);
                context.SaveChanges();
            }

            foreach (var movieDirectorName in movieDTO.MovieDirectors)
            {
                Director newDirector = new Director();
                newDirector.DirectorName = movieDirectorName;
                context.Directors.Add(newDirector);
                context.SaveChanges();

                Director director = context.Directors.FirstOrDefault(d => d.DirectorName == movieDirectorName);

                MovieDirector movieDirector = new MovieDirector();
                movieDirector.ImdbId     = movieDTO.ImdbId;
                movieDirector.DirectorId = director.DirectorId;
                context.MovieDirectors.Add(movieDirector);
                context.SaveChanges();
            }

            foreach (var movieGenreName in movieDTO.MovieGenres)
            {
                Genre newGenre = new Genre();
                newGenre.GenreName = movieGenreName;
                context.Genres.Add(newGenre);
                context.SaveChanges();

                Genre genre = context.Genres.FirstOrDefault(a => a.GenreName == movieGenreName);

                MovieGenre movieGenre = new MovieGenre();
                movieGenre.ImdbId  = movieDTO.ImdbId;
                movieGenre.GenreId = genre.GenreId;
                context.MovieGenres.Add(movieGenre);
                context.SaveChanges();
            }

            foreach (var movieLanguageName in movieDTO.MovieLanguages)
            {
                Language newLanguage = new Language();
                newLanguage.LanguageName = movieLanguageName;
                context.Languages.Add(newLanguage);
                context.SaveChanges();

                Language language = context.Languages.FirstOrDefault(a => a.LanguageName == movieLanguageName);

                MovieLanguage movieLanguage = new MovieLanguage();
                movieLanguage.ImdbId     = movieDTO.ImdbId;
                movieLanguage.LanguageId = language.LanguageId;
                context.MovieLanguages.Add(movieLanguage);
                context.SaveChanges();
            }

            foreach (var movieTagName in movieDTO.MovieTags)
            {
                Tag newTag = new Tag();
                newTag.TagName  = movieTagName;
                newTag.IsBanned = false;
                context.Tags.Add(newTag);
                context.SaveChanges();

                MovieTag movieTag = new MovieTag();
                movieTag.ImdbId  = movieDTO.ImdbId;
                movieTag.TagName = movieTagName;
                movieTag.VoteSum = 1;
                context.MovieTags.Add(movieTag);
                context.SaveChanges();
            }
        }
Esempio n. 12
0
 public void AddToMovieLanguages(MovieLanguage movieLanguage)
 {
     base.AddObject("MovieLanguages", movieLanguage);
 }
Esempio n. 13
0
 public static MovieLanguage CreateMovieLanguage(long id)
 {
     MovieLanguage movieLanguage = new MovieLanguage();
     movieLanguage.Id = id;
     return movieLanguage;
 }