mirror of https://github.com/Sonarr/Sonarr
64 lines
1.8 KiB
C#
64 lines
1.8 KiB
C#
using System.Linq;
|
|
using NzbDrone.Core.Datastore;
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
|
|
namespace NzbDrone.Core.Tv
|
|
{
|
|
public interface ISeriesRepository : IBasicRepository<Series>
|
|
{
|
|
bool SeriesPathExists(string path);
|
|
Series FindByTitle(string cleanTitle);
|
|
Series FindByTitle(string cleanTitle, int year);
|
|
Series FindByTvdbId(int tvdbId);
|
|
Series FindByTvRageId(int tvRageId);
|
|
Series FindByPath(string path);
|
|
}
|
|
|
|
public class SeriesRepository : BasicRepository<Series>, ISeriesRepository
|
|
{
|
|
public SeriesRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
|
: base(database, eventAggregator)
|
|
{
|
|
}
|
|
|
|
public bool SeriesPathExists(string path)
|
|
{
|
|
return Query.Where(c => c.Path == path).Any();
|
|
}
|
|
|
|
public Series FindByTitle(string cleanTitle)
|
|
{
|
|
cleanTitle = cleanTitle.ToLowerInvariant();
|
|
|
|
return Query.Where(s => s.CleanTitle == cleanTitle)
|
|
.SingleOrDefault();
|
|
}
|
|
|
|
public Series FindByTitle(string cleanTitle, int year)
|
|
{
|
|
cleanTitle = cleanTitle.ToLowerInvariant();
|
|
|
|
return Query.Where(s => s.CleanTitle == cleanTitle)
|
|
.AndWhere(s => s.Year == year)
|
|
.SingleOrDefault();
|
|
}
|
|
|
|
public Series FindByTvdbId(int tvdbId)
|
|
{
|
|
return Query.Where(s => s.TvdbId == tvdbId).SingleOrDefault();
|
|
}
|
|
|
|
public Series FindByTvRageId(int tvRageId)
|
|
{
|
|
return Query.Where(s => s.TvRageId == tvRageId).SingleOrDefault();
|
|
}
|
|
|
|
public Series FindByPath(string path)
|
|
{
|
|
return Query.Where(s => s.Path == path)
|
|
.FirstOrDefault();
|
|
}
|
|
}
|
|
}
|