Sonarr/src/NzbDrone.Core/Tv/SeriesRepository.cs

64 lines
1.8 KiB
C#
Raw Normal View History

using System.Linq;
2013-02-19 06:56:02 +00:00
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Events;
2013-09-11 06:33:47 +00:00
2013-02-19 06:56:02 +00:00
namespace NzbDrone.Core.Tv
{
2013-03-24 04:16:00 +00:00
public interface ISeriesRepository : IBasicRepository<Series>
2013-02-19 06:56:02 +00:00
{
bool SeriesPathExists(string path);
Series FindByTitle(string cleanTitle);
Series FindByTitle(string cleanTitle, int year);
2013-03-02 18:25:39 +00:00
Series FindByTvdbId(int tvdbId);
Series FindByTvRageId(int tvRageId);
Series FindByPath(string path);
2013-02-19 06:56:02 +00:00
}
2013-03-24 04:16:00 +00:00
public class SeriesRepository : BasicRepository<Series>, ISeriesRepository
2013-02-19 06:56:02 +00:00
{
public SeriesRepository(IMainDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
2013-02-19 06:56:02 +00:00
{
}
public bool SeriesPathExists(string path)
{
return Query.Where(c => c.Path == path).Any();
2013-02-19 06:56:02 +00:00
}
public Series FindByTitle(string cleanTitle)
2013-02-19 06:56:02 +00:00
{
cleanTitle = cleanTitle.ToLowerInvariant();
return Query.Where(s => s.CleanTitle == cleanTitle)
.SingleOrDefault();
2013-02-19 06:56:02 +00:00
}
2013-03-02 18:25:39 +00:00
public Series FindByTitle(string cleanTitle, int year)
{
cleanTitle = cleanTitle.ToLowerInvariant();
return Query.Where(s => s.CleanTitle == cleanTitle)
.AndWhere(s => s.Year == year)
.SingleOrDefault();
}
2013-03-02 18:25:39 +00:00
public Series FindByTvdbId(int tvdbId)
{
return Query.Where(s => s.TvdbId == tvdbId).SingleOrDefault();
2013-03-02 18:25:39 +00:00
}
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();
}
2013-02-19 06:56:02 +00:00
}
}