mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-05 02:22:31 +01:00
Get by multiple ids added to BasicRepo
This commit is contained in:
parent
ebf82ec09e
commit
c3273b74e8
@ -15,6 +15,7 @@ namespace NzbDrone.Core.Datastore
|
|||||||
IEnumerable<TModel> All();
|
IEnumerable<TModel> All();
|
||||||
int Count();
|
int Count();
|
||||||
TModel Get(int id);
|
TModel Get(int id);
|
||||||
|
IEnumerable<TModel> Get(IEnumerable<int> ids);
|
||||||
TModel SingleOrDefault();
|
TModel SingleOrDefault();
|
||||||
TModel Insert(TModel model);
|
TModel Insert(TModel model);
|
||||||
TModel Update(TModel model);
|
TModel Update(TModel model);
|
||||||
@ -64,6 +65,18 @@ public TModel Get(int id)
|
|||||||
return _dataMapper.Query<TModel>().Single(c => c.Id == id);
|
return _dataMapper.Query<TModel>().Single(c => c.Id == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<TModel> Get(IEnumerable<int> 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()
|
public TModel SingleOrDefault()
|
||||||
{
|
{
|
||||||
return All().Single();
|
return All().Single();
|
||||||
|
@ -13,7 +13,6 @@ public interface ISeriesRepository : IBasicRepository<Series>
|
|||||||
Series FindByTvdbId(int tvdbId);
|
Series FindByTvdbId(int tvdbId);
|
||||||
void SetSeriesType(int seriesId, SeriesTypes seriesTypes);
|
void SetSeriesType(int seriesId, SeriesTypes seriesTypes);
|
||||||
void SetTvRageId(int seriesId, int tvRageId);
|
void SetTvRageId(int seriesId, int tvRageId);
|
||||||
List<Series> SeriesIsInList(IEnumerable<int> ids);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SeriesRepository : BasicRepository<Series>, ISeriesRepository
|
public class SeriesRepository : BasicRepository<Series>, ISeriesRepository
|
||||||
@ -52,10 +51,5 @@ public void SetTvRageId(int seriesId, int tvRageId)
|
|||||||
{
|
{
|
||||||
SetFields(new Series { Id = seriesId, TvRageId = tvRageId }, s => s.TvRageId);
|
SetFields(new Series { Id = seriesId, TvRageId = tvRageId }, s => s.TvRageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Series> SeriesIsInList(IEnumerable<int> ids)
|
|
||||||
{
|
|
||||||
return Query.Where(String.Format("Id IN ({0})", String.Join(",", ids)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -137,11 +137,6 @@ public void UpdateFromSeriesEditor(IList<Series> editedSeries)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTvRageId(int seriesId, int tvRageId)
|
|
||||||
{
|
|
||||||
_seriesRepository.SetTvRageId(seriesId, tvRageId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Series FindByTvdbId(int tvdbId)
|
public Series FindByTvdbId(int tvdbId)
|
||||||
{
|
{
|
||||||
return _seriesRepository.FindByTvdbId(tvdbId);
|
return _seriesRepository.FindByTvdbId(tvdbId);
|
||||||
@ -181,7 +176,7 @@ public bool SeriesPathExists(string folder)
|
|||||||
|
|
||||||
public List<Series> GetSeriesInList(IEnumerable<int> seriesIds)
|
public List<Series> GetSeriesInList(IEnumerable<int> seriesIds)
|
||||||
{
|
{
|
||||||
return _seriesRepository.SeriesIsInList(seriesIds);
|
return _seriesRepository.Get(seriesIds).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleAsync(SeriesAddedEvent message)
|
public void HandleAsync(SeriesAddedEvent message)
|
||||||
|
Loading…
Reference in New Issue
Block a user