2013-02-20 02:05:15 +00:00
|
|
|
using System.Collections.Generic;
|
2013-03-24 00:08:23 +00:00
|
|
|
using System.Data;
|
2013-02-20 02:05:15 +00:00
|
|
|
using System.Linq;
|
|
|
|
using NzbDrone.Core.Datastore;
|
2013-03-24 00:08:23 +00:00
|
|
|
using ServiceStack.OrmLite;
|
2013-02-20 02:05:15 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Tv
|
|
|
|
{
|
2013-03-24 00:08:23 +00:00
|
|
|
public interface ISeasonRepository : IBasicDb<Season>
|
2013-02-20 02:05:15 +00:00
|
|
|
{
|
|
|
|
IList<int> GetSeasonNumbers(int seriesId);
|
|
|
|
Season Get(int seriesId, int seasonNumber);
|
|
|
|
bool IsIgnored(int seriesId, int seasonNumber);
|
|
|
|
List<Season> GetSeasonBySeries(int seriesId);
|
|
|
|
}
|
|
|
|
|
2013-03-24 00:08:23 +00:00
|
|
|
public class SeasonRepository : BasicDb<Season>, ISeasonRepository
|
2013-02-20 02:05:15 +00:00
|
|
|
{
|
2013-03-24 00:08:23 +00:00
|
|
|
private readonly IDbConnection _database;
|
|
|
|
|
|
|
|
public SeasonRepository(IDbConnection database)
|
|
|
|
: base(database)
|
2013-02-20 02:05:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public IList<int> GetSeasonNumbers(int seriesId)
|
|
|
|
{
|
2013-03-24 00:08:23 +00:00
|
|
|
return _database.List<int>("SELECT SeasonNumber WHERE SeriesId = {0}", seriesId);
|
2013-02-20 02:05:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Season Get(int seriesId, int seasonNumber)
|
|
|
|
{
|
2013-03-24 00:08:23 +00:00
|
|
|
return _database.Select<Season>(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber).Single();
|
2013-02-20 02:05:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsIgnored(int seriesId, int seasonNumber)
|
|
|
|
{
|
2013-03-24 00:08:23 +00:00
|
|
|
var season = _database.Select<Season>(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber).SingleOrDefault();
|
2013-02-25 00:00:17 +00:00
|
|
|
|
|
|
|
if(season == null) return false;
|
|
|
|
|
|
|
|
return season.Ignored;
|
2013-02-20 02:05:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<Season> GetSeasonBySeries(int seriesId)
|
|
|
|
{
|
2013-03-24 00:08:23 +00:00
|
|
|
return _database.Select<Season>(s => s.SeriesId == seriesId);
|
2013-02-20 02:05:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|