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

99 lines
3.6 KiB
C#
Raw Normal View History

using System.Linq;
using System.Web.Mvc;
2011-12-02 04:33:17 +03:00
using NzbDrone.Core.Jobs;
using NzbDrone.Core.Providers;
using NzbDrone.Web.Models;
using Telerik.Web.Mvc;
namespace NzbDrone.Web.Controllers
{
public class HistoryController : Controller
{
2011-04-10 05:44:01 +03:00
private readonly HistoryProvider _historyProvider;
private readonly JobProvider _jobProvider;
public HistoryController(HistoryProvider historyProvider, JobProvider jobProvider)
{
_historyProvider = historyProvider;
_jobProvider = jobProvider;
}
public ActionResult Index()
{
var history = _historyProvider.AllItemsWithRelationships().Select(h => new HistoryModel
{
HistoryId = h.HistoryId,
SeriesId = h.SeriesId,
SeasonNumber = h.Episode.SeasonNumber,
EpisodeNumber = h.Episode.EpisodeNumber,
EpisodeTitle = h.Episode.Title,
EpisodeOverview = h.Episode.Overview,
SeriesTitle = h.SeriesTitle,
NzbTitle = h.NzbTitle,
Quality = h.Quality.ToString(),
IsProper = h.IsProper,
Date = h.Date,
Indexer = h.Indexer,
EpisodeId = h.EpisodeId
}).ToList();
return View(history);
}
public JsonResult Trim()
{
_historyProvider.Trim();
return JsonNotificationResult.Info("Trimmed History");
}
public JsonResult Purge()
{
_historyProvider.Purge();
return JsonNotificationResult.Info("History Cleared");
}
[HttpPost]
public JsonResult Delete(int historyId)
{
//Delete the existing item from history
_historyProvider.Delete(historyId);
return JsonNotificationResult.Info("History Item Deleted");
}
[HttpPost]
public JsonResult Redownload(int historyId, int episodeId)
{
//Delete the existing item from history
_historyProvider.Delete(historyId);
//Queue a job to download the replacement episode
_jobProvider.QueueJob(typeof(EpisodeSearchJob), episodeId);
return JsonNotificationResult.Info("Episode Redownload Started");
}
[GridAction]
public ActionResult _AjaxBinding()
{
var history = _historyProvider.AllItemsWithRelationships().Select(h => new HistoryModel
{
HistoryId = h.HistoryId,
SeriesId = h.SeriesId,
SeasonNumber = h.Episode.SeasonNumber,
EpisodeNumber = h.Episode.EpisodeNumber,
EpisodeTitle = h.Episode.Title,
EpisodeOverview = h.Episode.Overview,
SeriesTitle = h.SeriesTitle,
NzbTitle = h.NzbTitle,
Quality = h.Quality.ToString(),
IsProper = h.IsProper,
Date = h.Date,
Indexer = h.Indexer,
EpisodeId = h.EpisodeId
});
return View(new GridModel(history));
}
}
2011-04-10 05:44:01 +03:00
}