1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-31 07:52:37 +01:00
Sonarr/NzbDrone.Core/Tv/SeasonRepository.cs

50 lines
1.5 KiB
C#
Raw Normal View History

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