1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Core/History/HistoryRepository.cs

43 lines
1.1 KiB
C#
Raw Normal View History

2013-02-24 00:29:22 +03:00
using System;
2013-03-24 07:16:00 +03:00
using System.Data;
2013-02-24 00:29:22 +03:00
using System.Linq;
2013-05-06 00:24:33 +03:00
using NzbDrone.Common.Messaging;
2013-02-24 00:29:22 +03:00
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.History
{
public interface IHistoryRepository : IBasicRepository<History>
{
void Trim();
2013-03-25 04:38:11 +03:00
QualityModel GetBestQualityInHistory(int episodeId);
2013-02-24 00:29:22 +03:00
}
public class HistoryRepository : BasicRepository<History>, IHistoryRepository
{
2013-05-06 00:24:33 +03:00
public HistoryRepository(IDatabase database, IMessageAggregator messageAggregator)
: base(database, messageAggregator)
2013-02-24 00:29:22 +03:00
{
}
public void Trim()
{
2013-03-27 06:44:52 +03:00
var cutoff = DateTime.Now.AddDays(-30).Date;
Delete(c=> c.Date < cutoff);
2013-02-24 00:29:22 +03:00
}
2013-03-25 04:38:11 +03:00
public QualityModel GetBestQualityInHistory(int episodeId)
2013-02-24 00:29:22 +03:00
{
2013-03-27 06:44:52 +03:00
var history = Query.Where(c => c.EpisodeId == episodeId)
2013-03-24 07:16:00 +03:00
.OrderByDescending(c => c.Quality).FirstOrDefault();
2013-02-24 00:29:22 +03:00
if (history != null)
{
return history.Quality;
}
return null;
}
}
}