Radarr/NzbDrone.Core/History/HistoryRepository.cs

43 lines
1.1 KiB
C#
Raw Normal View History

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;
2013-05-05 21:24:33 +00:00
using NzbDrone.Common.Messaging;
2013-02-23 21:29:22 +00:00
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-05-05 21:24:33 +00:00
public HistoryRepository(IDatabase database, IMessageAggregator messageAggregator)
: base(database, messageAggregator)
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;
}
}
}