sonarr-repo-only/NzbDrone.Core/Tv/SeasonRepository.cs

50 lines
1.4 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2013-03-24 00:08:23 +00:00
using System.Data;
using System.Linq;
using NzbDrone.Core.Datastore;
2013-03-25 03:51:32 +00:00
namespace NzbDrone.Core.Tv
{
2013-03-24 04:16:00 +00:00
public interface ISeasonRepository : IBasicRepository<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 04:16:00 +00:00
public class SeasonRepository : BasicRepository<Season>, ISeasonRepository
{
2013-03-24 00:08:23 +00:00
private readonly IDbConnection _database;
2013-03-25 03:51:32 +00:00
public SeasonRepository(IDatabase database)
2013-03-24 00:08:23 +00:00
: base(database)
{
}
public IList<int> GetSeasonNumbers(int seriesId)
{
2013-03-25 03:51:32 +00:00
return Queryable().Where(c => c.SeriesId == seriesId).Select(c => c.SeriesId).ToList();
}
public Season Get(int seriesId, int seasonNumber)
{
2013-03-25 03:51:32 +00:00
return Queryable().Single(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber);
}
public bool IsIgnored(int seriesId, int seasonNumber)
{
2013-03-25 03:51:32 +00:00
var season = Queryable().SingleOrDefault(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber);
2013-02-25 00:00:17 +00:00
2013-03-25 03:51:32 +00:00
if (season == null) return false;
2013-02-25 00:00:17 +00:00
return season.Ignored;
}
public List<Season> GetSeasonBySeries(int seriesId)
{
2013-03-25 03:51:32 +00:00
return Queryable().Where(s => s.SeriesId == seriesId);
}
}
}