HistoryProvider will return History Items with Episode and SeriesTitle.

This commit is contained in:
Mark McDowall 2011-06-19 16:44:45 -07:00
parent 5c055ebb9a
commit 0972c956b8
3 changed files with 29 additions and 24 deletions

View File

@ -25,9 +25,18 @@ namespace NzbDrone.Core.Providers
{ {
} }
public virtual IEnumerable<History> AllItems() public virtual List<History> AllItems()
{ {
return _database.Query<History>(""); return _database.Fetch<History>("");
}
public virtual List<History> AllItemsWithRelationships()
{
return _database.Fetch<History, Episode>(@"
SELECT History.*, Series.Title as SeriesTitle, Episodes.* FROM History
INNER JOIN Series ON History.SeriesId = Series.SeriesId
INNER JOIN Episodes ON History.EpisodeId = Episodes.EpisodeId
");
} }
public virtual void Purge() public virtual void Purge()

View File

@ -16,5 +16,11 @@ namespace NzbDrone.Core.Repository
public DateTime Date { get; set; } public DateTime Date { get; set; }
public bool IsProper { get; set; } public bool IsProper { get; set; }
public string Indexer { get; set; } public string Indexer { get; set; }
[ResultColumn]
public Episode Episode { get; set; }
[ResultColumn]
public string SeriesTitle { get; set; }
} }
} }

View File

@ -46,30 +46,20 @@ namespace NzbDrone.Web.Controllers
[GridAction] [GridAction]
public ActionResult _AjaxBinding() public ActionResult _AjaxBinding()
{ {
var historyDb = _historyProvider.AllItems(); var history = _historyProvider.AllItemsWithRelationships().Select(h => new HistoryModel
var history = new List<HistoryModel>();
foreach (var item in historyDb)
{
var episode = _episodeProvider.GetEpisode(item.EpisodeId);
var series = _seriesProvider.GetSeries(item.SeriesId);
history.Add(new HistoryModel
{ {
HistoryId = item.HistoryId, HistoryId = h.HistoryId,
SeasonNumber = episode.SeasonNumber, SeasonNumber = h.Episode.SeasonNumber,
EpisodeNumber = episode.EpisodeNumber, EpisodeNumber = h.Episode.EpisodeNumber,
EpisodeTitle = episode.Title, EpisodeTitle = h.Episode.Title,
EpisodeOverview = episode.Overview, EpisodeOverview = h.Episode.Overview,
SeriesTitle = series.Title, SeriesTitle = h.SeriesTitle,
NzbTitle = item.NzbTitle, NzbTitle = h.NzbTitle,
Quality = item.Quality.ToString(), Quality = h.Quality.ToString(),
IsProper = item.IsProper, IsProper = h.IsProper,
Date = item.Date, Date = h.Date,
Indexer = item.Indexer Indexer = h.Indexer
}); });
}
return View(new GridModel(history)); return View(new GridModel(history));
} }