/// <summary> /// Add a new entry into the database only if it doesn't exist /// </summary> /// <param name="collection">A collection object containing the information of the movie</param> /// <returns>A boolean to inform if anything was added</returns> public bool Insert(fmmCollection collection) { int rowsAffected = DBConnection.Execute(@" INSERT OR IGNORE INTO collection VALUES ( @id, @name, @poster );", collection ); if (rowsAffected > 0) { return(true); } return(false); }
/// <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); } }