コード例 #1
0
 public Subtitles Update(Subtitles subtitles)
 {
     var subs = _context.Subtitles.FirstOrDefault(cp => cp.Id == subtitles.Id);
     if (subs == null) throw new ArgumentException();
     _context.Entry(subtitles).State = System.Data.Entity.EntityState.Modified;
     _context.SaveChanges();
     return subs;
 }
コード例 #2
0
 public Subtitles Create(Subtitles subtitles)
 {
     var subs = _context.Subtitles.Add(subtitles);
     _context.SaveChanges();
     return subs;
 }
コード例 #3
0
 public Subtitles Delete(Subtitles subtitles)
 {
     var subs = _context.Subtitles.Remove(subtitles);
     _context.SaveChanges();
     return subs;
 }
コード例 #4
0
 private void UpdateDatabaseWithWatchable(CompleteWatchable watchable, DatabaseBuilderType type, string path = "")
 {
     if (type == DatabaseBuilderType.Movies)
     {
         var files = Directory.GetFileSystemEntries(path).ToList();
         var actors = new List<Actor>(watchable.Actors);
         var writers = new List<Writer>(watchable.Writers);
         var directors = new List<Director>(watchable.Directors);
         var genres = new List<Genre>(watchable.Genres);
         watchable.Actors.Clear();
         watchable.Writers.Clear();
         watchable.Directors.Clear();
         watchable.Genres.Clear();
         _moviesRepository.Create((Movie)watchable);
         foreach (var file in files)
         {
             if (file.EndsWith("srt"))
             {
                 if (files.Count > 2)
                     BasicLogger.Log(watchable.Title +
                                       "'s subtitles not added due to more than 2 files being present in the directory.", Verbosity.Error);
                 else
                 {
                     var subs = new Subtitles
                     {
                         Language = SubtitleLanguage.English,
                         Path = file,
                         Watchable = watchable
                     };
                     _subtitlesRepository.Create(subs);
                 }
             }
             else if (file.EndsWith("mp4") || file.EndsWith("avi") || file.EndsWith("mkv") || file.EndsWith("wmv"))
             {
                 watchable.Path = file;
                 _moviesRepository.Update((Movie)watchable);
             }
         }
         foreach (var actor in actors)
         {
             var databaseActor = _actorsRepository.Query(x => x.Name == actor.Name).FirstOrDefault();
             if (databaseActor == null)
             {
                 actor.Watchables = new List<Watchable>{watchable};
                 _actorsRepository.Create(actor);
             }
             else
             {
                 if(databaseActor.Watchables == null)
                     databaseActor.Watchables = new List<Watchable>();
                 if (databaseActor.Watchables.Contains(watchable)) continue;
                 databaseActor.Watchables.Add(watchable);
                 _actorsRepository.Update(databaseActor);
             }
         }
         foreach (var writer in writers)
         {
             var databaseWriter = _writersRepository.Query(x => x.Name == writer.Name).FirstOrDefault();
             if (databaseWriter == null)
             {
                 writer.Watchables = new List<Watchable> { watchable };
                 _writersRepository.Create(writer);
             }
             else
             {
                 if (databaseWriter.Watchables == null)
                     databaseWriter.Watchables = new List<Watchable>();
                 if (databaseWriter.Watchables.Contains(watchable)) continue;
                 databaseWriter.Watchables.Add(watchable);
                 _writersRepository.Update(databaseWriter);
             }
         }
         foreach (var director in directors)
         {
             var databaseDirector = _directorsRepository.Query(x => x.Name == director.Name).FirstOrDefault();
             if (databaseDirector == null)
             {
                 director.Watchables = new List<Watchable> { watchable };
                 _directorsRepository.Create(director);
             }
             else
             {
                 if (databaseDirector.Watchables == null)
                     databaseDirector.Watchables = new List<Watchable>();
                 if (databaseDirector.Watchables.Contains(watchable)) continue;
                 databaseDirector.Watchables.Add(watchable);
                 _directorsRepository.Update(databaseDirector);
             }
         }
         foreach (var genre in genres)
         {
             var databaseGenre = _genresRepository.Query(x => x.Name == genre.Name).FirstOrDefault();
             if (databaseGenre == null)
             {
                 genre.Watchables = new List<Watchable> { watchable };
                 _genresRepository.Create(genre);
             }
             else
             {
                 if (databaseGenre.Watchables == null)
                     databaseGenre.Watchables = new List<Watchable>();
                 if (databaseGenre.Watchables.Contains(watchable)) continue;
                 databaseGenre.Watchables.Add(watchable);
                 _genresRepository.Update(databaseGenre);
             }
         }
     }
 }