sonarr-repo-only/NzbDrone.Core/History/HistoryRepository.cs

41 lines
1.3 KiB
C#
Raw Normal View History

2013-02-23 21:29:22 +00:00
using System;
using System.Linq;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.History
{
public interface IHistoryRepository : IBasicRepository<History>
{
void Trim();
QualityModel GetBestQualityInHistory(int seriesId, int seasonNumber, int episodeNumber);
}
public class HistoryRepository : BasicRepository<History>, IHistoryRepository
{
public HistoryRepository(IObjectDatabase objectDatabase)
: base(objectDatabase)
{
}
public void Trim()
{
var oldIds = Queryable.Where(c => c.Date < DateTime.Now.AddDays(-30).Date).Select(c => c.OID);
DeleteMany(oldIds);
}
public QualityModel GetBestQualityInHistory(int seriesId, int seasonNumber, int episodeNumber)
{
2013-02-24 19:57:33 +00:00
var history = Queryable.OrderByDescending(c => c.Quality).FirstOrDefault(c => c.Episode.Series.OID == seriesId && c.Episode.SeasonNumber == seasonNumber &&
2013-02-23 21:29:22 +00:00
c.Episode.EpisodeNumber == episodeNumber);
if (history != null)
{
return history.Quality;
}
return null;
}
}
}