From 9d24ccd97a548334407838063932eecc71c82085 Mon Sep 17 00:00:00 2001 From: markus101 Date: Tue, 22 Feb 2011 22:23:59 -0800 Subject: [PATCH] Fixes for Episode to EpisodeFile mapping. Series details sorts with newest season and newest episode on top my default. --- NzbDrone.Core/Providers/EpisodeProvider.cs | 5 +++++ NzbDrone.Core/Providers/IEpisodeProvider.cs | 1 + NzbDrone.Core/Providers/MediaFileProvider.cs | 7 ++++--- NzbDrone.Core/Repository/EpisodeFile.cs | 2 +- NzbDrone.Web/Controllers/SeriesController.cs | 15 ++++++++++++++- NzbDrone.Web/Views/Series/Details.aspx | 8 +++++--- 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index e9f3c84b0..873ed636e 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -263,6 +263,11 @@ public void DeleteEpisode(int episodeId) _sonicRepo.Delete(episodeId); } + public void UpdateEpisode(Episode episode) + { + _sonicRepo.Update(episode); + } + private bool IsSeasonIgnored(EpisodeModel episode) { //Check if this Season is ignored diff --git a/NzbDrone.Core/Providers/IEpisodeProvider.cs b/NzbDrone.Core/Providers/IEpisodeProvider.cs index 17c70ddce..c9d1104e5 100644 --- a/NzbDrone.Core/Providers/IEpisodeProvider.cs +++ b/NzbDrone.Core/Providers/IEpisodeProvider.cs @@ -23,5 +23,6 @@ public interface IEpisodeProvider void RefreshEpisodeInfo(Season season); IList GetEpisodeBySeason(long seasonId); void DeleteEpisode(int episodeId); + void UpdateEpisode(Episode episode); } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/MediaFileProvider.cs b/NzbDrone.Core/Providers/MediaFileProvider.cs index 409fb2d3c..4ad520dc6 100644 --- a/NzbDrone.Core/Providers/MediaFileProvider.cs +++ b/NzbDrone.Core/Providers/MediaFileProvider.cs @@ -75,17 +75,18 @@ public EpisodeFile ImportFile(Series series, string filePath) var episodeFile = new EpisodeFile(); episodeFile.DateAdded = DateTime.Now; episodeFile.SeriesId = series.SeriesId; - episodeFile.Episodes = episodes; episodeFile.Path = Parser.NormalizePath(filePath); episodeFile.Size = _diskProvider.GetSize(filePath); episodeFile.Quality = Parser.ParseQuality(filePath); episodeFile.Proper = Parser.ParseProper(filePath); - _repository.Add(episodeFile); + var fileId = (int)_repository.Add(episodeFile); - //This is for logging, a little ugly... + //This is for logging + updating the episodes that are linked to this EpisodeFile string episodeList = String.Empty; foreach (var ep in episodes) { + ep.FileId = fileId; + _episodeProvider.UpdateEpisode(ep); episodeList += String.Format(", {0}", ep.EpisodeId).Trim(' ', ','); } Logger.Trace("File {0}:{1} attached to episode(s): '{2}'", episodeFile.FileId, filePath, episodeList); diff --git a/NzbDrone.Core/Repository/EpisodeFile.cs b/NzbDrone.Core/Repository/EpisodeFile.cs index 959be4658..890d2de2d 100644 --- a/NzbDrone.Core/Repository/EpisodeFile.cs +++ b/NzbDrone.Core/Repository/EpisodeFile.cs @@ -17,6 +17,6 @@ public class EpisodeFile public DateTime DateAdded { get; set; } [SubSonicToManyRelation] - public virtual List Episodes { get; set; } + public virtual List Episodes { get; private set; } } } diff --git a/NzbDrone.Web/Controllers/SeriesController.cs b/NzbDrone.Web/Controllers/SeriesController.cs index 35640e59a..539e773fd 100644 --- a/NzbDrone.Web/Controllers/SeriesController.cs +++ b/NzbDrone.Web/Controllers/SeriesController.cs @@ -19,16 +19,20 @@ public class SeriesController : Controller private readonly ISyncProvider _syncProvider; private readonly IRssSyncProvider _rssSyncProvider; private readonly IQualityProvider _qualityProvider; + private readonly IMediaFileProvider _mediaFileProvider; // // GET: /Series/ - public SeriesController(ISyncProvider syncProvider, ISeriesProvider seriesProvider, IEpisodeProvider episodeProvider, IRssSyncProvider rssSyncProvider, IQualityProvider qualityProvider) + public SeriesController(ISyncProvider syncProvider, ISeriesProvider seriesProvider, + IEpisodeProvider episodeProvider, IRssSyncProvider rssSyncProvider, + IQualityProvider qualityProvider, IMediaFileProvider mediaFileProvider) { _seriesProvider = seriesProvider; _episodeProvider = episodeProvider; _syncProvider = syncProvider; _rssSyncProvider = rssSyncProvider; _qualityProvider = qualityProvider; + _mediaFileProvider = mediaFileProvider; } public ActionResult Index() @@ -189,5 +193,14 @@ public ActionResult Delete(int seriesId) return RedirectToAction("Index", "Series"); } + + public ActionResult SyncEpisodesOnDisk(int seriesId) + { + //Syncs the episodes on disk for the specified series + var series = _seriesProvider.GetSeries(seriesId); + _mediaFileProvider.Scan(series); + + return RedirectToAction("Details", new { seriesId }); + } } } diff --git a/NzbDrone.Web/Views/Series/Details.aspx b/NzbDrone.Web/Views/Series/Details.aspx index 9714dfe6f..810731fdb 100644 --- a/NzbDrone.Web/Views/Series/Details.aspx +++ b/NzbDrone.Web/Views/Series/Details.aspx @@ -33,10 +33,11 @@
<%: Model.Path %>
+ <% //Todo: This breaks when using SQLServer... thoughts? //Normal Seasons - foreach (var season in Model.Seasons.Where(s => s.SeasonNumber > 0)) + foreach (var season in Model.Seasons.Where(s => s.SeasonNumber > 0).Reverse()) { %>
@@ -55,7 +56,7 @@ }) //.DetailView(detailView => detailView.Template(e => Html.RenderPartial("EpisodeDetail", e))) .DetailView(detailView => detailView.ClientTemplate("
<#= Overview #>
")) - .Sortable(rows => rows.OrderBy(epSort => epSort.Add(c => c.EpisodeNumber)).Enabled(false)) + .Sortable(rows => rows.OrderBy(epSort => epSort.Add(c => c.EpisodeNumber).Descending()).Enabled(true)) .Footer(false) .DataBinding(d => d.Ajax().Select("_AjaxSeasonGrid", "Series", new RouteValueDictionary { { "seasonId", season1.SeasonId.ToString() } })) //.EnableCustomBinding(true) @@ -89,7 +90,8 @@ Html.Telerik().Grid(specialSeasons.Episodes).Name("seasons_specials") %>

<%: Html.ActionLink("Edit", "Edit", new {seriesId = Model.SeriesId}) %> | - <%: Html.ActionLink("Back to Series", "Index") %> + <%: Html.ActionLink("Back to Series List", "Index") %> | + <%: Html.ActionLink("Sync Episodes on Disk", "SyncEpisodesOnDisk", new {seriesId = Model.SeriesId}) %>