This commit is contained in:
tidusjar 2016-09-12 14:15:17 +01:00
commit a1bf73f137
3 changed files with 43 additions and 12 deletions

View file

@ -65,7 +65,7 @@ namespace PlexRequests.Helpers.Tests
"ProviderId", "ImdbId", "TvDbId", "Overview", "Title", "PosterPath", "ReleaseDate", "Type", "ProviderId", "ImdbId", "TvDbId", "Overview", "Title", "PosterPath", "ReleaseDate", "Type",
"Status", "Approved", "RequestedBy", "RequestedDate", "Available", "Issues", "OtherMessage", "AdminNote", "Status", "Approved", "RequestedBy", "RequestedDate", "Available", "Issues", "OtherMessage", "AdminNote",
"SeasonList", "SeasonCount", "SeasonsRequested", "MusicBrainzId", "RequestedUsers","ArtistName", "SeasonList", "SeasonCount", "SeasonsRequested", "MusicBrainzId", "RequestedUsers","ArtistName",
"ArtistId","IssueId","Episodes","AllUsers","CanApprove","Id" "ArtistId","IssueId","Episodes", "Denied", "DeniedReason", "AllUsers","CanApprove","Id",
}).SetName("Requested Model"); }).SetName("Requested Model");
} }
} }

View file

@ -35,6 +35,7 @@ using PlexRequests.Api.Models.Sonarr;
using PlexRequests.Core.SettingModels; using PlexRequests.Core.SettingModels;
using PlexRequests.Store; using PlexRequests.Store;
using System.Linq; using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using PlexRequests.Helpers.Exceptions; using PlexRequests.Helpers.Exceptions;
@ -70,7 +71,7 @@ namespace PlexRequests.UI.Helpers
{ {
int.TryParse(sonarrSettings.QualityProfile, out qualityProfile); int.TryParse(sonarrSettings.QualityProfile, out qualityProfile);
} }
var series = await GetSonarrSeries(sonarrSettings, model.ProviderId); var series = await GetSonarrSeries(sonarrSettings, model.ProviderId);
if (episodeRequest) if (episodeRequest)
@ -81,7 +82,7 @@ namespace PlexRequests.UI.Helpers
// Series Exists // Series Exists
// Request the episodes in the existing series // Request the episodes in the existing series
await RequestEpisodesWithExistingSeries(model, series, sonarrSettings); await RequestEpisodesWithExistingSeries(model, series, sonarrSettings);
return new SonarrAddSeries {title = series.title}; return new SonarrAddSeries { title = series.title };
} }
@ -93,7 +94,7 @@ namespace PlexRequests.UI.Helpers
// Get the series that was just added // Get the series that was just added
series = await GetSonarrSeries(sonarrSettings, model.ProviderId); series = await GetSonarrSeries(sonarrSettings, model.ProviderId);
series.monitored = false; // Un-monitor the series series.monitored = true; // We want to make sure we are monitoring the series
// Un-monitor all seasons // Un-monitor all seasons
foreach (var season in series.seasons) foreach (var season in series.seasons)
@ -113,15 +114,44 @@ namespace PlexRequests.UI.Helpers
if (series != null) if (series != null)
{ {
// Monitor the seasons that we have chosen var requestAll = model.SeasonsRequested.Equals("All", StringComparison.CurrentCultureIgnoreCase);
foreach (var season in series.seasons) var first = model.SeasonsRequested.Equals("First", StringComparison.CurrentCultureIgnoreCase);
var latest = model.SeasonsRequested.Equals("Latest", StringComparison.CurrentCultureIgnoreCase);
if (model.SeasonList.Any())
{ {
if (model.SeasonList.Contains(season.seasonNumber)) // Monitor the seasons that we have chosen
foreach (var season in series.seasons)
{
if (model.SeasonList.Contains(season.seasonNumber))
{
season.monitored = true;
}
}
}
if (requestAll)
{
// Monitor all seasons
foreach (var season in series.seasons)
{ {
season.monitored = true; season.monitored = true;
} }
} }
if (first)
{
var firstSeries = series?.seasons?.OrderBy(x => x.seasonNumber)?.FirstOrDefault() ?? new Season();
firstSeries.monitored = true;
}
if (latest)
{
var lastSeries = series?.seasons?.OrderByDescending(x => x.seasonNumber)?.FirstOrDefault() ?? new Season();
lastSeries.monitored = true;
}
// Update the series in sonarr with the new monitored status // Update the series in sonarr with the new monitored status
SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri); SonarrApi.UpdateSeries(series, sonarrSettings.ApiKey, sonarrSettings.FullUri);
await RequestAllEpisodesInASeasonWithExistingSeries(model, series, sonarrSettings); await RequestAllEpisodesInASeasonWithExistingSeries(model, series, sonarrSettings);
@ -201,7 +231,7 @@ namespace PlexRequests.UI.Helpers
var tasks = new List<Task>(); var tasks = new List<Task>();
foreach (var r in episodes) foreach (var r in episodes)
{ {
if(r.monitored || r.hasFile) // If it's already montiored or has the file, there is no point in updating it if (r.monitored || r.hasFile) // If it's already montiored or has the file, there is no point in updating it
{ {
continue; continue;
} }

View file

@ -53,14 +53,15 @@ namespace PlexRequests.UI.Modules
private Response CheckAuth() private Response CheckAuth()
{ {
var settings = PlexRequestSettings.GetSettings(); var settings = PlexRequestSettings.GetSettings();
var baseUrl = settings.BaseUrl;
// Have we been through the wizard? // Have we been through the wizard?
if (!settings.Wizard) if (!settings.Wizard)
{ {
return Context.GetRedirect("~/wizard"); return Context.GetRedirect(string.IsNullOrEmpty(baseUrl) ? "~/wizard" : $"~/{baseUrl}/wizard");
} }
var baseUrl = settings.BaseUrl;
var redirectPath = string.IsNullOrEmpty(baseUrl) ? "~/userlogin" : $"~/{baseUrl}/userlogin"; var redirectPath = string.IsNullOrEmpty(baseUrl) ? "~/userlogin" : $"~/{baseUrl}/userlogin";
return Session[SessionKeys.UsernameKey] == null return Session[SessionKeys.UsernameKey] == null
@ -68,4 +69,4 @@ namespace PlexRequests.UI.Modules
: null; : null;
} }
} }
} }