Пример #1
0
        /// <summary>
        /// Insert a company in DB
        /// </summary>
        /// <param name="company">fmmCompany object to insert in DB</param>
        /// <param name="movieID">Id of the movie the company is linked to</param>
        /// <returns>True or false</returns>
        public bool Insert(fmmCompany company, int movieID)
        {
            int rowsAffected = this.DBConnection.Execute(@"
                INSERT OR IGNORE INTO
                    company 
                VALUES (
                    @id,
                    @name
                );",
                                                         company
                                                         );

            rowsAffected = this.DBConnection.Execute(@"
                INSERT OR IGNORE INTO
                    production_company
                VALUES (
                    @fk_movie, 
                    @fk_company
                );",

                                                     new {
                fk_movie   = movieID,
                fk_company = company.id
            }
                                                     );

            dbh.Disconnect(DBConnection);

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Populate DB with movie returned by API
        /// </summary>
        /// <param name="infos">Movie information</param>
        /// <param name="credit">Cast and crew linked to movie</param>
        /// <param name="originalName">Orignial Name of the movie</param>
        /// <param name="originalFilePath">Original name of the file</param>
        private void PopulateDB(Movie infos, Credits credit, string originalName, string originalFilePath)
        {
            MovieRepository      _movieRepo      = new MovieRepository();
            CollectionRepository _collectionRepo = new CollectionRepository();
            CrewRepository       _crewrepo       = new CrewRepository();
            CastRepository       _castrepo       = new CastRepository();
            CompanyRepository    _companyrepo    = new CompanyRepository();
            CountryRepository    _countryrepo    = new CountryRepository();
            GenreRepository      _genrerepo      = new GenreRepository();
            LanguageRepository   _languagerepo   = new LanguageRepository();


            bool collectionAdded = false;

            if (infos.BelongsToCollection != null)
            {
                fmmCollection collection = new fmmCollection {
                    id     = infos.BelongsToCollection.Id,
                    name   = infos.BelongsToCollection.Name,
                    poster = infos.BelongsToCollection.PosterPath
                };
                _collectionRepo.Insert(collection);

                collectionAdded = true;
            }

            fmmMovie movie = new fmmMovie {
                id          = infos.Id,
                imdbid      = infos.ImdbId,
                title       = infos.Title,
                ogtitle     = originalName,
                filename    = Path.GetFileName(originalFilePath),
                filepath    = originalFilePath,
                adult       = infos.Adult,
                budget      = infos.Budget,
                homepage    = infos.Homepage,
                runtime     = infos.Runtime,
                tagline     = infos.Tagline,
                voteaverage = infos.VoteAverage,
                oglanguage  = infos.OriginalLanguage,
                overview    = infos.Overview,
                popularity  = infos.Popularity,
                poster      = infos.PosterPath,
                releasedate = infos.ReleaseDate.ToString().Substring(0, 10)
            };

            if (collectionAdded)
            {
                movie.fk_collection = infos.BelongsToCollection.Id;
            }

            bool movieAdded = _movieRepo.Insert(movie);

            foreach (Crew crew in credit.Crew)
            {
                var ncrew = new fmmCrew {
                    id         = crew.Id,
                    creditid   = crew.CreditId,
                    name       = crew.Name,
                    image      = crew.ProfilePath,
                    department = crew.Department,
                    job        = crew.Job
                };

                _crewrepo.Insert(ncrew, movie.id);
            }

            foreach (Cast cast in credit.Cast)
            {
                var ncast = new fmmCast {
                    id        = cast.Id,
                    castid    = cast.CastId,
                    creditid  = cast.CreditId,
                    name      = cast.Name,
                    image     = cast.ProfilePath,
                    character = cast.Character,
                    aorder    = cast.Order
                };

                _castrepo.Insert(ncast, movie.id);
            }

            foreach (ProductionCompany company in infos.ProductionCompanies)
            {
                var ncompany = new fmmCompany {
                    id   = company.Id,
                    name = company.Name,
                };

                _companyrepo.Insert(ncompany, movie.id);
            }

            foreach (ProductionCountry country in infos.ProductionCountries)
            {
                var ncountry = new fmmCountry {
                    name = country.Name,
                };

                _countryrepo.Insert(ncountry, movie.id);
            }

            foreach (Genre genre in infos.Genres)
            {
                var ngenre = new fmmGenre {
                    id   = genre.Id,
                    name = genre.Name,
                };

                _genrerepo.Insert(ngenre, movie.id);
            }


            foreach (SpokenLanguage language in infos.SpokenLanguages)
            {
                var nlanguage = new fmmLanguage {
                    name = language.Name,
                };

                _languagerepo.Insert(nlanguage, movie.id);
            }
        }