1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-28 19:05:55 +00:00
Radarr/NzbDrone.Core/Providers/SeasonProvider.cs

92 lines
2.8 KiB
C#
Raw Normal View History

2010-10-05 06:21:18 +00:00
using System;
using System.Collections.Generic;
2011-04-10 02:44:01 +00:00
using System.Linq;
2010-10-05 06:21:18 +00:00
using NLog;
using NzbDrone.Core.Repository;
2010-10-05 06:21:18 +00:00
using SubSonic.Repository;
namespace NzbDrone.Core.Providers
{
public class SeasonProvider
2010-10-05 06:21:18 +00:00
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IRepository _repository;
2010-10-05 06:21:18 +00:00
public SeasonProvider(IRepository repository)
2010-10-05 06:21:18 +00:00
{
_repository = repository;
2010-10-05 06:21:18 +00:00
}
public SeasonProvider()
{
}
public virtual Season GetSeason(int seasonId)
2010-10-05 06:21:18 +00:00
{
return _repository.Single<Season>(seasonId);
2010-10-05 06:21:18 +00:00
}
public virtual Season GetSeason(int seriesId, int seasonNumber)
{
return _repository.Single<Season>(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber);
}
public virtual List<Season> GetSeasons(int seriesId)
2010-10-05 06:21:18 +00:00
{
return _repository.All<Season>().Where(s => s.SeriesId == seriesId).ToList();
2010-10-05 06:21:18 +00:00
}
public virtual Season GetLatestSeason(int seriesId)
2011-02-10 06:41:24 +00:00
{
return _repository.All<Season>().Where(s => s.SeriesId == seriesId).OrderBy(s => s.SeasonNumber).Last();
2011-02-10 06:41:24 +00:00
}
public virtual void EnsureSeason(int seriesId, int seasonId, int seasonNumber)
2010-10-05 06:21:18 +00:00
{
if (_repository.Exists<Season>(s => s.SeasonId == seasonId))
2010-10-05 06:21:18 +00:00
return;
//TODO: Calculate Season Folder
2011-04-10 02:44:01 +00:00
Logger.Trace("Adding Season To DB. [SeriesID:{0} SeasonID:{1} SeasonNumber:{2}]", seriesId, seasonId,
seasonNumber, "????");
var newSeason = new Season
{
Monitored = true,
SeasonId = seasonId,
SeasonNumber = seasonNumber,
SeriesId = seriesId
};
_repository.Add(newSeason);
2010-10-05 06:21:18 +00:00
}
public virtual int SaveSeason(Season season)
2010-10-05 06:21:18 +00:00
{
if (_repository.Exists<Season>(s => s.SeasonId == season.SeasonId))
{
return _repository.Update(season);
}
return (int)_repository.Add(season);
2010-10-05 06:21:18 +00:00
}
public virtual bool IsIgnored(int seasonId)
{
if (_repository.Single<Season>(seasonId).Monitored)
return false;
Logger.Debug("Season {0} is not wanted.");
return true;
}
public virtual bool IsIgnored(int seriesId, int seasonNumber)
{
var season = _repository.Single<Season>(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber);
return !season.Monitored;
}
public void DeleteSeason(int seasonId)
{
_repository.Delete<Season>(seasonId);
}
2010-10-05 06:21:18 +00:00
}
}