2013-02-23 21:29:22 +00:00
|
|
|
|
using System;
|
2013-03-24 04:16:00 +00:00
|
|
|
|
using System.Data;
|
2013-02-23 21:29:22 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2013-03-24 04:16:00 +00:00
|
|
|
|
public HistoryRepository(IDbConnection database)
|
|
|
|
|
: base(database)
|
2013-02-23 21:29:22 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Trim()
|
|
|
|
|
{
|
2013-03-24 04:16:00 +00:00
|
|
|
|
var oldIds = Where(c => c.Date < DateTime.Now.AddDays(-30).Date).Select(c => c.Id);
|
2013-02-23 21:29:22 +00:00
|
|
|
|
DeleteMany(oldIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public QualityModel GetBestQualityInHistory(int seriesId, int seasonNumber, int episodeNumber)
|
|
|
|
|
{
|
2013-03-24 04:16:00 +00:00
|
|
|
|
var history = Where(c => c.Episode.Series.Id == seriesId && c.Episode.SeasonNumber == seasonNumber && c.Episode.EpisodeNumber == episodeNumber)
|
|
|
|
|
.OrderByDescending(c => c.Quality).FirstOrDefault();
|
2013-02-23 21:29:22 +00:00
|
|
|
|
|
|
|
|
|
if (history != null)
|
|
|
|
|
{
|
|
|
|
|
return history.Quality;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|