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

42 lines
1.0 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;
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-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);
}
2013-03-25 01:38:11 +00:00
public QualityModel GetBestQualityInHistory(int episodeId)
2013-02-23 21:29:22 +00:00
{
2013-03-25 01:38:11 +00:00
var history = 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;
}
}
}