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();
|
2013-03-25 01:38:11 +00:00
|
|
|
|
QualityModel GetBestQualityInHistory(int episodeId);
|
2013-02-23 21:29:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class HistoryRepository : BasicRepository<History>, IHistoryRepository
|
|
|
|
|
{
|
2013-03-25 03:51:32 +00:00
|
|
|
|
public HistoryRepository(IDatabase database)
|
2013-03-24 04:16:00 +00:00
|
|
|
|
: base(database)
|
2013-02-23 21:29:22 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Trim()
|
|
|
|
|
{
|
2013-03-27 03:44:52 +00:00
|
|
|
|
var cutoff = DateTime.Now.AddDays(-30).Date;
|
|
|
|
|
Delete(c=> c.Date < cutoff);
|
2013-02-23 21:29:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-03-25 01:38:11 +00:00
|
|
|
|
public QualityModel GetBestQualityInHistory(int episodeId)
|
2013-02-23 21:29:22 +00:00
|
|
|
|
{
|
2013-03-27 03:44:52 +00:00
|
|
|
|
var history = Query.Where(c => c.EpisodeId == episodeId)
|
2013-03-24 04:16:00 +00:00
|
|
|
|
.OrderByDescending(c => c.Quality).FirstOrDefault();
|
2013-02-23 21:29:22 +00:00
|
|
|
|
|
|
|
|
|
if (history != null)
|
|
|
|
|
{
|
|
|
|
|
return history.Quality;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|