예제 #1
0
        public ActionResult AddMovie(MovieAddEditModel model)
        {
            model.MovieName.LanguageID = ParseHelper.ToInt32(model.NameLanguageID);
            model.MovieName.IsDefault  = true;

            //model.MovieArchive.ArchiveID = Parse.ToInt32(model.ArchiveID);
            //model.MovieArchive.Resolution = model.ArchiveResolution;
            //model.MovieArchive.FileExtension = model.ArchiveFileExtension;
            //model.MovieArchive.UserID = model.

            //insert movie first and get inserted id
            int movieId = MovieBL.Save(model.Movie, UserID);

            //save the name
            model.MovieName.MovieID = movieId;
            MovieNameBL.Save(model.MovieName, UserID);
            //if (model.ArchiveExists == true)
            //{
            //    //save the archive
            //    model.MovieArchive.MovieID = movieId;
            //    MovieArchiveBL.Save(model.MovieArchive, UserID);
            //}

            switch (model.Submit)
            {
            case "SubmitAndNavigateToMovie":
                return(RedirectToAction("DetailView", "Movie", new { id = movieId }));

            case "SubmitAndClearForm":
            default:
                return(RedirectToAction("AddMovie"));
            }
        }
예제 #2
0
        public ActionResult EditMovie(MovieAddEditModel model)
        {
            int movieId = model.MovieId;

            MovieDO     _movie     = MovieBL.GetMovie(movieId);
            MovieNameDO _movieName = MovieNameBL.GetAllDOByMovieID(movieId).SingleOrDefault(q => q.IsDefault == true);

            //MovieArchiveDO _movieArchive = MovieArchiveBL.GetAllDOByMovieID(movieId).SingleOrDefault();
            //if (_movieArchive == null) _movieArchive = new MovieArchiveDO() { MovieID = movieId };

            _movieName.LanguageID = ParseHelper.ToInt32(model.NameLanguageID);
            _movieName.Name       = model.MovieName.Name;

            //_movieArchive.ArchiveID = Parse.ToInt32(model.ArchiveID);
            //_movieArchive.Resolution = model.ArchiveResolution;
            //_movieArchive.FileExtension = model.ArchiveFileExtension;
            //_movieArchive.Path = model.MovieArchive.Path;

            //if imdbid is changed, we need to reset imdb things first.
            string previousImdbId = _movie.ImdbID;

            if (string.IsNullOrEmpty(previousImdbId) == false && model.Movie.ImdbID != previousImdbId)
            {
                MovieBL.ResetImdbInformation(model.MovieId);
                _movie        = MovieBL.GetMovie(movieId);
                _movie.ImdbID = model.Movie.ImdbID;
            }

            //save movie
            MovieBL.Save(_movie, UserID);
            //save the name
            MovieNameBL.Save(_movieName, UserID);
            //if (model.ArchiveExists == true)
            //{
            //    //save the archive
            //    MovieArchiveBL.Save(_movieArchive, UserID);
            //}

            switch (model.Submit)
            {
            case "SubmitAndNavigateToMovie":
                return(RedirectToAction("DetailView", "Movie", new { id = movieId }));

            case "SubmitAndClearForm":
            default:
                return(RedirectToAction("AddMovie"));
            }
        }
예제 #3
0
        private void getMovieInfoByIdAndSave(string imdbId, MovieDO movie, TextWriter tw, DateTime start)
        {
            ImdbModel imdbInfo = new ImdbModel( );

            try {
                imdbInfo = ImdbHelper.getMovieInformation(imdbId, tw, start);

                logHelper.logLine(tw, "Imdb information parsed successfully. Starting operation 'Basic Info'");

                #region Basic Info (not updated in db yet)
                if (string.IsNullOrEmpty(movie.ImdbID))
                {
                    movie.ImdbID = imdbId;
                }
                if (string.IsNullOrEmpty(movie.ImdbPoster) && !string.IsNullOrEmpty(imdbInfo.picturePath))
                {
                    string savePath = getSavePath( );
                    string fileName = FileSystemHelper.prepareFileNameForPicture(imdbInfo.picturePath.Substring(imdbInfo.picturePath.LastIndexOf('/')), new MovieNameModel {
                        OriginalName = movie.OriginalName
                    }, savePath);
                    WebRequestHelper.Download(imdbInfo.picturePath, savePath + fileName);
                    movie.ImdbPoster = fileName;
                }

                movie.ImdbRating = imdbInfo.imdbRating;
                if (movie.Year == null || movie.Year == 0)
                {
                    movie.Year = imdbInfo.year;
                }
                #endregion Basic Info

                logHelper.logLine(tw, "Basic Info inserted");

                logHelper.logLine(tw, "Starting operation 'Genres'");

                #region types
                if (MovieTypeBL.GetAllByMovieID(movie.ID).Count() < 1)
                {
                    try {
                        if (imdbInfo.genres != null)
                        {
                            foreach (string item in imdbInfo.genres)
                            {
                                if (allTypes.ContainsKey(item))
                                {
                                    MovieTypeBL.Save(new MovieTypeDO( )
                                    {
                                        MovieID = movie.ID, TypeID = allTypes[item]
                                    }, 1);
                                }
                                else
                                {
                                    int currentID = TypeBL.Save(new MArchive.Domain.Lookup.TypeDO( )
                                    {
                                        Name = item
                                    }, 1).ID;
                                    //MovieTypeBL.Save( movie.ID, item, 1 );
                                    MovieTypeBL.Save(new MovieTypeDO( )
                                    {
                                        MovieID = movie.ID, TypeID = currentID
                                    }, 1);
                                    allTypes.Add(item, currentID);
                                }
                            }
                        }
                        logHelper.logLine(tw, "Genres inserted");
                    } catch (Exception ex) {
                        logHelper.logLine(tw, "Genres could not be inserted.");
                        logHelper.logException(tw, ex);
                        logHelper.logLine(tw);
                    }
                }
                #endregion types

                logHelper.logLine(tw, "Starting operation 'Actors'");

                #region actors
                if (MovieActorBL.GetAllByMovieID(movie.ID).Count( ) < 1)
                {
                    try {
                        if (imdbInfo.cast != null)
                        {
                            foreach (string item in imdbInfo.cast)
                            {
                                if (allActors.ContainsKey(item))
                                {
                                    MovieActorBL.Save(new MovieActorDO( )
                                    {
                                        MovieID = movie.ID, ActorID = allActors[item]
                                    }, 1);
                                }
                                else
                                {
                                    int currentID = ActorBL.Save(new MArchive.Domain.Lookup.ActorDO( )
                                    {
                                        Name = item
                                    }, 1).ID;
                                    MovieActorBL.Save(new MovieActorDO( )
                                    {
                                        MovieID = movie.ID, ActorID = currentID
                                    }, 1);
                                    allActors.Add(item, currentID);
                                }
                            }
                        }
                        logHelper.logLine(tw, "Actors inserted");
                    } catch (Exception ex) {
                        logHelper.logLine(tw, "Actors could not be inserted.");
                        logHelper.logException(tw, ex);
                        logHelper.logLine(tw);
                    }
                }
                #endregion actors

                logHelper.logLine(tw, "Starting operation 'Languages'");

                #region languages
                if (MovieLanguageBL.GetAllByMovieID(movie.ID).Count( ) < 1)
                {
                    try {
                        if (imdbInfo.languages != null)
                        {
                            foreach (string item in imdbInfo.languages)
                            {
                                if (allLanguages.ContainsKey(item))
                                {
                                    MovieLanguageBL.Save(new MovieLanguageDO( )
                                    {
                                        MovieID = movie.ID, LanguageID = allLanguages[item]
                                    }, 1);
                                }
                                else
                                {
                                    int currentID = LanguageBL.Save(new MArchive.Domain.Lookup.LanguageDO( )
                                    {
                                        Name = item
                                    }, 1).ID;
                                    MovieLanguageBL.Save(new MovieLanguageDO( )
                                    {
                                        MovieID = movie.ID, LanguageID = currentID
                                    }, 1);
                                    allLanguages.Add(item, currentID);
                                }
                            }
                        }
                        logHelper.logLine(tw, "Languages inserted");
                    } catch (Exception ex) {
                        logHelper.logLine(tw, "Languages could not be inserted.");
                        logHelper.logException(tw, ex);
                        logHelper.logLine(tw);
                    }
                }
                #endregion languages

                logHelper.logLine(tw, "Starting operation 'Directors'");

                #region directors
                if (MovieDirectorBL.GetAllByMovieID(movie.ID).Count( ) < 1)
                {
                    try {
                        if (imdbInfo.directors != null)
                        {
                            foreach (string item in imdbInfo.directors)
                            {
                                if (allDirectors.ContainsKey(item))
                                {
                                    MovieDirectorBL.Save(new MovieDirectorDO( )
                                    {
                                        MovieID = movie.ID, DirectorID = allDirectors[item]
                                    }, 1);
                                }
                                else
                                {
                                    int currentID = DirectorBL.Save(new MArchive.Domain.Lookup.DirectorDO( )
                                    {
                                        Name = item
                                    }, 1).ID;
                                    MovieDirectorBL.Save(new MovieDirectorDO( )
                                    {
                                        MovieID = movie.ID, DirectorID = currentID
                                    }, 1);
                                    allDirectors.Add(item, currentID);
                                }
                            }
                        }
                        logHelper.logLine(tw, "Directors inserted");
                    } catch (Exception ex) {
                        logHelper.logLine(tw, "Directors could not be inserted.");
                        logHelper.logException(tw, ex);
                        logHelper.logLine(tw);
                    }
                }
                #endregion directors

                logHelper.logLine(tw, "Starting operation 'Writers'");

                #region writers
                if (MovieWriterBL.GetAllByMovieID(movie.ID).Count( ) < 1)
                {
                    try {
                        if (imdbInfo.writers != null)
                        {
                            foreach (string item in imdbInfo.writers)
                            {
                                if (allWriters.ContainsKey(item))
                                {
                                    MovieWriterBL.Save(new MovieWriterDO( )
                                    {
                                        MovieID = movie.ID, WriterID = allWriters[item]
                                    }, 1);
                                }
                                else
                                {
                                    int currentID = WriterBL.Save(new MArchive.Domain.Lookup.WriterDO( )
                                    {
                                        Name = item
                                    }, 1).ID;
                                    MovieWriterBL.Save(new MovieWriterDO( )
                                    {
                                        MovieID = movie.ID, WriterID = currentID
                                    }, 1);
                                    allWriters.Add(item, currentID);
                                }
                            }
                        }
                        logHelper.logLine(tw, "Writers inserted");
                    } catch (Exception ex) {
                        logHelper.logLine(tw, "Writers could not be inserted.");
                        logHelper.logException(tw, ex);
                        logHelper.logLine(tw);
                    }
                }
                #endregion writers

                logHelper.logLine(tw, "Updating 'movie' table");

                movie.ImdbParsed        = true;
                movie.ImdbLastParseDate = movie.UpdateDate = DateTime.Now;

                MovieBL.Save(movie, 1);

                logHelper.logLine(tw, "Table update successful");
            } catch (Exception ex) { logHelper.logException(tw, ex); }
        }