diff --git a/src/NzbDrone.Core/Extras/Files/ExtraFileRepository.cs b/src/NzbDrone.Core/Extras/Files/ExtraFileRepository.cs index 36a7bddc6d..56d6e98211 100644 --- a/src/NzbDrone.Core/Extras/Files/ExtraFileRepository.cs +++ b/src/NzbDrone.Core/Extras/Files/ExtraFileRepository.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging.Events; @@ -11,6 +12,7 @@ public interface IExtraFileRepository : IBasicRepository void DeleteForMovieFile(int movieFileId); List GetFilesByMovie(int movieId); List GetFilesByMovieFile(int movieFileId); + TExtraFile FindByPath(int movieId, string path); } public class ExtraFileRepository : BasicRepository, IExtraFileRepository @@ -40,5 +42,10 @@ public List GetFilesByMovieFile(int movieFileId) { return Query(x => x.MovieFileId == movieFileId); } + + public TExtraFile FindByPath(int movieId, string path) + { + return Query(c => c.MovieId == movieId && c.RelativePath == path).SingleOrDefault(); + } } } diff --git a/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs b/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs index 8768f13224..cee6f48b8a 100644 --- a/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs +++ b/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs @@ -18,6 +18,7 @@ public interface IExtraFileService { List GetFilesByMovie(int movieId); List GetFilesByMovieFile(int movieFileId); + TExtraFile FindByPath(int movieId, string path); void Upsert(TExtraFile extraFile); void Upsert(List extraFiles); void Delete(int id); @@ -58,6 +59,11 @@ public List GetFilesByMovieFile(int movieFileId) return _repository.GetFilesByMovieFile(movieFileId); } + public TExtraFile FindByPath(int movieId, string path) + { + return _repository.FindByPath(movieId, path); + } + public void Upsert(TExtraFile extraFile) { Upsert(new List { extraFile }); diff --git a/src/NzbDrone.Core/Extras/Others/OtherExtraFileRenamer.cs b/src/NzbDrone.Core/Extras/Others/OtherExtraFileRenamer.cs index 4f68b2e37b..9c3e4a92fa 100644 --- a/src/NzbDrone.Core/Extras/Others/OtherExtraFileRenamer.cs +++ b/src/NzbDrone.Core/Extras/Others/OtherExtraFileRenamer.cs @@ -1,4 +1,3 @@ -using System.Linq; using NLog; using NzbDrone.Common.Disk; using NzbDrone.Common.Extensions; @@ -38,8 +37,8 @@ public void RenameOtherExtraFile(Movie movie, string path) } var relativePath = movie.Path.GetRelativePath(path); + var otherExtraFile = _otherExtraFileService.FindByPath(movie.Id, relativePath); - var otherExtraFile = _otherExtraFileService.GetFilesByMovie(movie.Id).Where(e => e.RelativePath == relativePath).SingleOrDefault(); if (otherExtraFile != null) { var newPath = path + "-orig"; @@ -63,8 +62,8 @@ private void RemoveOtherExtraFile(Movie movie, string path) } var relativePath = movie.Path.GetRelativePath(path); + var otherExtraFile = _otherExtraFileService.FindByPath(movie.Id, relativePath); - var otherExtraFile = _otherExtraFileService.GetFilesByMovie(movie.Id).Where(e => e.RelativePath == relativePath).SingleOrDefault(); if (otherExtraFile != null) { _recycleBinProvider.DeleteFile(path);