From c3273b74e8cae9fc688fc602e08ee39b0d0ad49f Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 17 Apr 2013 17:33:38 -0700 Subject: [PATCH] Get by multiple ids added to BasicRepo --- NzbDrone.Core/Datastore/BasicRepository.cs | 13 +++++++++++++ NzbDrone.Core/Tv/SeriesRepository.cs | 6 ------ NzbDrone.Core/Tv/SeriesService.cs | 7 +------ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/NzbDrone.Core/Datastore/BasicRepository.cs b/NzbDrone.Core/Datastore/BasicRepository.cs index 71f2604e7..c0041ac18 100644 --- a/NzbDrone.Core/Datastore/BasicRepository.cs +++ b/NzbDrone.Core/Datastore/BasicRepository.cs @@ -15,6 +15,7 @@ namespace NzbDrone.Core.Datastore IEnumerable All(); int Count(); TModel Get(int id); + IEnumerable Get(IEnumerable ids); TModel SingleOrDefault(); TModel Insert(TModel model); TModel Update(TModel model); @@ -64,6 +65,18 @@ public TModel Get(int id) return _dataMapper.Query().Single(c => c.Id == id); } + public IEnumerable Get(IEnumerable ids) + { + var idList = ids.ToList(); + var result = Query.Where(String.Format("Id IN ({0})", String.Join(",", idList))).ToList(); + var resultCount = result.Count; + + if (resultCount != idList.Count || result.Select(r => r.Id).Distinct().Count() != resultCount) + throw new InvalidOperationException("Unexpected result from query"); + + return result; + } + public TModel SingleOrDefault() { return All().Single(); diff --git a/NzbDrone.Core/Tv/SeriesRepository.cs b/NzbDrone.Core/Tv/SeriesRepository.cs index 7cb0e3aad..02190c5c0 100644 --- a/NzbDrone.Core/Tv/SeriesRepository.cs +++ b/NzbDrone.Core/Tv/SeriesRepository.cs @@ -13,7 +13,6 @@ public interface ISeriesRepository : IBasicRepository Series FindByTvdbId(int tvdbId); void SetSeriesType(int seriesId, SeriesTypes seriesTypes); void SetTvRageId(int seriesId, int tvRageId); - List SeriesIsInList(IEnumerable ids); } public class SeriesRepository : BasicRepository, ISeriesRepository @@ -52,10 +51,5 @@ public void SetTvRageId(int seriesId, int tvRageId) { SetFields(new Series { Id = seriesId, TvRageId = tvRageId }, s => s.TvRageId); } - - public List SeriesIsInList(IEnumerable ids) - { - return Query.Where(String.Format("Id IN ({0})", String.Join(",", ids))); - } } } \ No newline at end of file diff --git a/NzbDrone.Core/Tv/SeriesService.cs b/NzbDrone.Core/Tv/SeriesService.cs index bf547db97..34b2e669c 100644 --- a/NzbDrone.Core/Tv/SeriesService.cs +++ b/NzbDrone.Core/Tv/SeriesService.cs @@ -137,11 +137,6 @@ public void UpdateFromSeriesEditor(IList editedSeries) } - public void SetTvRageId(int seriesId, int tvRageId) - { - _seriesRepository.SetTvRageId(seriesId, tvRageId); - } - public Series FindByTvdbId(int tvdbId) { return _seriesRepository.FindByTvdbId(tvdbId); @@ -181,7 +176,7 @@ public bool SeriesPathExists(string folder) public List GetSeriesInList(IEnumerable seriesIds) { - return _seriesRepository.SeriesIsInList(seriesIds); + return _seriesRepository.Get(seriesIds).ToList(); } public void HandleAsync(SeriesAddedEvent message)