2013-04-14 18:41:39 -07:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2013-03-24 20:51:32 -07:00
|
|
|
using System.Linq;
|
2013-05-05 14:24:33 -07:00
|
|
|
using NzbDrone.Common.Messaging;
|
2013-02-18 22:56:02 -08:00
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Tv
|
|
|
|
{
|
2013-03-23 21:16:00 -07:00
|
|
|
public interface ISeriesRepository : IBasicRepository<Series>
|
2013-02-18 22:56:02 -08:00
|
|
|
{
|
|
|
|
bool SeriesPathExists(string path);
|
|
|
|
List<Series> Search(string title);
|
2013-04-14 18:41:39 -07:00
|
|
|
Series FindByTitle(string cleanTitle);
|
2013-03-02 10:25:39 -08:00
|
|
|
Series FindByTvdbId(int tvdbId);
|
2013-08-18 22:53:26 -07:00
|
|
|
Series FindByTvRageId(int tvRageId);
|
2013-03-03 21:53:02 -08:00
|
|
|
void SetSeriesType(int seriesId, SeriesTypes seriesTypes);
|
2013-05-03 19:30:44 -07:00
|
|
|
Series FindBySlug(string slug);
|
2013-08-02 00:16:37 -07:00
|
|
|
List<String> GetSeriesPaths();
|
2013-02-18 22:56:02 -08:00
|
|
|
}
|
|
|
|
|
2013-03-23 21:16:00 -07:00
|
|
|
public class SeriesRepository : BasicRepository<Series>, ISeriesRepository
|
2013-02-18 22:56:02 -08:00
|
|
|
{
|
2013-05-05 14:24:33 -07:00
|
|
|
public SeriesRepository(IDatabase database, IMessageAggregator messageAggregator)
|
|
|
|
: base(database, messageAggregator)
|
2013-02-18 22:56:02 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool SeriesPathExists(string path)
|
|
|
|
{
|
2013-03-26 20:44:52 -07:00
|
|
|
return Query.Any(c => c.Path == path);
|
2013-02-18 22:56:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<Series> Search(string title)
|
|
|
|
{
|
2013-03-26 20:44:52 -07:00
|
|
|
return Query.Where(s => s.Title.Contains(title));
|
2013-02-18 22:56:02 -08:00
|
|
|
}
|
|
|
|
|
2013-04-14 18:41:39 -07:00
|
|
|
public Series FindByTitle(string cleanTitle)
|
2013-02-18 22:56:02 -08:00
|
|
|
{
|
2013-04-14 18:41:39 -07:00
|
|
|
return Query.SingleOrDefault(s => s.CleanTitle.Equals(cleanTitle, StringComparison.InvariantCultureIgnoreCase));
|
2013-02-18 22:56:02 -08:00
|
|
|
}
|
2013-03-02 10:25:39 -08:00
|
|
|
|
|
|
|
public Series FindByTvdbId(int tvdbId)
|
|
|
|
{
|
2013-04-16 23:55:39 -07:00
|
|
|
return Query.SingleOrDefault(s => s.TvdbId.Equals(tvdbId));
|
2013-03-02 10:25:39 -08:00
|
|
|
}
|
|
|
|
|
2013-08-18 22:53:26 -07:00
|
|
|
public Series FindByTvRageId(int tvRageId)
|
|
|
|
{
|
|
|
|
return Query.SingleOrDefault(s => s.TvRageId.Equals(tvRageId));
|
|
|
|
}
|
|
|
|
|
2013-03-23 17:08:23 -07:00
|
|
|
public void SetSeriesType(int seriesId, SeriesTypes seriesType)
|
2013-03-02 10:25:39 -08:00
|
|
|
{
|
2013-03-26 23:16:55 -07:00
|
|
|
SetFields(new Series { Id = seriesId, SeriesType = seriesType }, s => s.SeriesType);
|
2013-03-02 10:25:39 -08:00
|
|
|
}
|
2013-03-31 13:25:39 -07:00
|
|
|
|
2013-05-03 19:30:44 -07:00
|
|
|
public Series FindBySlug(string slug)
|
|
|
|
{
|
|
|
|
return Query.SingleOrDefault(c => c.TitleSlug == slug.ToLower());
|
|
|
|
}
|
2013-08-02 00:16:37 -07:00
|
|
|
|
|
|
|
public List<string> GetSeriesPaths()
|
|
|
|
{
|
|
|
|
return Query.Select(s => s.Path).ToList();
|
|
|
|
}
|
2013-02-18 22:56:02 -08:00
|
|
|
}
|
|
|
|
}
|