1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 00:12:30 +01:00
Sonarr/NzbDrone.Core/Tv/SeasonRepository.cs
2013-05-05 14:24:33 -07:00

49 lines
1.4 KiB
C#

using System.Collections.Generic;
using System.Linq;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.Tv
{
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);
}
public class SeasonRepository : BasicRepository<Season>, ISeasonRepository
{
public SeasonRepository(IDatabase database, IMessageAggregator messageAggregator)
: base(database, messageAggregator)
{
}
public IList<int> GetSeasonNumbers(int seriesId)
{
return Query.Where(c => c.SeriesId == seriesId).Select(c => c.SeasonNumber).ToList();
}
public Season Get(int seriesId, int seasonNumber)
{
return Query.Single(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber);
}
public bool IsIgnored(int seriesId, int seasonNumber)
{
var season = Query.SingleOrDefault(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber);
if (season == null) return false;
return season.Ignored;
}
public List<Season> GetSeasonBySeries(int seriesId)
{
return Query.Where(s => s.SeriesId == seriesId);
}
}
}