diff --git a/src/Ombi.Core.Tests/Engine/MovieRequestEngineTests.cs b/src/Ombi.Core.Tests/Engine/MovieRequestEngineTests.cs index 801472f4f..ec8f24d2d 100644 --- a/src/Ombi.Core.Tests/Engine/MovieRequestEngineTests.cs +++ b/src/Ombi.Core.Tests/Engine/MovieRequestEngineTests.cs @@ -16,7 +16,7 @@ namespace Ombi.Core.Tests.Engine { RequestService = new Mock>(); var requestService = new RequestService(null, RequestService.Object); - Engine = new MovieRequestEngine(null, requestService, null, null, null); + Engine = new MovieRequestEngine(null, requestService, null, null, null, null, null); } private MovieRequestEngine Engine { get; } diff --git a/src/Ombi.Core/Engine/MovieRequestEngine.cs b/src/Ombi.Core/Engine/MovieRequestEngine.cs index 61358cecf..68cd27f57 100644 --- a/src/Ombi.Core/Engine/MovieRequestEngine.cs +++ b/src/Ombi.Core/Engine/MovieRequestEngine.cs @@ -96,7 +96,7 @@ namespace Ombi.Core.Engine Status = movieInfo.Status, RequestedDate = DateTime.UtcNow, Approved = false, - RequestedUsers = new List { Username }, + RequestedUser =Username, Issues = IssueState.None }; @@ -191,7 +191,7 @@ namespace Ombi.Core.Engine results.OtherMessage = request.OtherMessage; results.Overview = request.Overview; results.PosterPath = request.PosterPath; - results.RequestedUsers = request.RequestedUsers?.ToList() ?? new List(); + results.RequestedUser = request.RequestedUser; var model = MovieRequestService.UpdateRequest(results); return model; @@ -202,21 +202,6 @@ namespace Ombi.Core.Engine await MovieRequestService.DeleteRequestAsync(requestId); } - private IEnumerable GetListDifferences(IEnumerable existing, - IEnumerable request) - { - var newRequest = request - .Select(r => - new EpisodesModel - { - SeasonNumber = r.SeasonNumber, - EpisodeNumber = r.EpisodeNumber - }) - .ToList(); - - return newRequest.Except(existing); - } - private async Task AddMovieRequest(MovieRequestModel model, string message) { await MovieRequestService.AddRequestAsync(model); diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs index 78c4d826c..5768ad6a7 100644 --- a/src/Ombi.Core/Engine/TvRequestEngine.cs +++ b/src/Ombi.Core/Engine/TvRequestEngine.cs @@ -71,7 +71,7 @@ namespace Ombi.Core.Engine Status = showInfo.status, RequestedDate = DateTime.UtcNow, Approved = false, - RequestedUsers = new List { Username }, + RequestedUser = Username, Issues = IssueState.None, ProviderId = tv.Id, RequestAll = tv.RequestAll, @@ -95,22 +95,22 @@ namespace Ombi.Core.Engine model.ChildRequests.Add(childRequest); - if (childRequest.SeasonRequests.Any()) - { - var episodes = await TvApi.EpisodeLookup(showInfo.id); + //if (childRequest.SeasonRequests.Any()) + //{ + // var episodes = await TvApi.EpisodeLookup(showInfo.id); - foreach (var e in episodes) - { - var season = childRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == e.season); - season?.Episodes.Add(new EpisodesRequested - { - Url = e.url, - Title = e.name, - AirDate = DateTime.Parse(e.airstamp), - EpisodeNumber = e.number - }); - } - } + // foreach (var e in episodes) + // { + // var season = childRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == e.season); + // season?.Episodes.Add(new EpisodesRequested + // { + // Url = e.url, + // Title = e.name, + // AirDate = DateTime.Parse(e.airstamp), + // EpisodeNumber = e.number + // }); + // } + //} if (tv.LatestSeason) { @@ -218,19 +218,45 @@ namespace Ombi.Core.Engine return await AfterRequest(newRequest); } - private IEnumerable GetListDifferences(IEnumerable existing, - IEnumerable request) + private IEnumerable GetListDifferences(List existing, + List request) { - var newRequest = request - .Select(r => - new SeasonRequestModel + var requestsToRemove = new List(); + foreach (var r in request) + { + // Do we have an existing season? + var existingSeason = existing.FirstOrDefault(x => x.SeasonNumber == r.SeasonNumber); + if (existingSeason == null) + { + continue; + } + + // Compare the episodes + for (var i = r.Episodes.Count - 1; i >= 0; i--) + { + var existingEpisode = existingSeason.Episodes.FirstOrDefault(x => x.EpisodeNumber == r.Episodes[i].EpisodeNumber); + if (existingEpisode == null) + { + // we are fine, we have not yet requested this + } + else { - SeasonNumber = r.SeasonNumber, - Episodes = r.Episodes - }) - .ToList(); + // We already have this request + r.Episodes.RemoveAt(i); + } + } - return newRequest.Except(existing); + if (!r.Episodes.Any()) + { + requestsToRemove.Add(r); + } + } + + foreach (var remove in requestsToRemove) + { + request.Remove(remove); + } + return request; } private async Task AddRequest(TvRequestModel model) diff --git a/src/Ombi.Core/Engine/TvSearchEngine.cs b/src/Ombi.Core/Engine/TvSearchEngine.cs index abc962136..01e735b9b 100644 --- a/src/Ombi.Core/Engine/TvSearchEngine.cs +++ b/src/Ombi.Core/Engine/TvSearchEngine.cs @@ -172,6 +172,7 @@ namespace Ombi.Core.Engine // Find the existing request season var existingSeason = existingRequestChildRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == season.SeasonNumber); + if(existingSeason == null) continue; foreach (var ep in existingSeason.Episodes) { diff --git a/src/Ombi.Core/Models/Requests/BaseRequestModel.cs b/src/Ombi.Core/Models/Requests/BaseRequestModel.cs index ac4732fa9..f40488af5 100644 --- a/src/Ombi.Core/Models/Requests/BaseRequestModel.cs +++ b/src/Ombi.Core/Models/Requests/BaseRequestModel.cs @@ -1,8 +1,6 @@ using Newtonsoft.Json; using Ombi.Store.Entities; using System; -using System.Collections.Generic; -using System.Linq; namespace Ombi.Core.Models.Requests { @@ -22,7 +20,7 @@ namespace Ombi.Core.Models.Requests public IssueState Issues { get; set; } public string OtherMessage { get; set; } public string AdminNote { get; set; } - public List RequestedUsers { get; set; } = new List(); + public string RequestedUser { get; set; } public int IssueId { get; set; } public bool Denied { get; set; } public string DeniedReason { get; set; } @@ -30,24 +28,13 @@ namespace Ombi.Core.Models.Requests [JsonIgnore] public bool Released => DateTime.UtcNow > ReleaseDate; - [JsonIgnore] - public IEnumerable AllUsers - { - get - { - var u = new List(); - if (RequestedUsers != null && RequestedUsers.Any()) - u.AddRange(RequestedUsers); - return u; - } - } [JsonIgnore] public bool CanApprove => !Approved && !Available; - + public bool UserHasRequested(string username) { - return AllUsers.Any(x => x.Equals(username, StringComparison.OrdinalIgnoreCase)); + return RequestedUser.Equals(username, StringComparison.OrdinalIgnoreCase); } } } \ No newline at end of file diff --git a/src/Ombi/ClientApp/app/interfaces/IRequestModel.ts b/src/Ombi/ClientApp/app/interfaces/IRequestModel.ts index 75ad6ee4d..21ce62ab5 100644 --- a/src/Ombi/ClientApp/app/interfaces/IRequestModel.ts +++ b/src/Ombi/ClientApp/app/interfaces/IRequestModel.ts @@ -14,7 +14,7 @@ available: boolean, otherMessage: string, adminNote: string, - requestedUser: string[], + requestedUser: string, issueId: number, denied: boolean, deniedReason: string, diff --git a/src/Ombi/ClientApp/app/requests/request.component.ts b/src/Ombi/ClientApp/app/requests/request.component.ts index 14d31ddd3..bd6d5bbae 100644 --- a/src/Ombi/ClientApp/app/requests/request.component.ts +++ b/src/Ombi/ClientApp/app/requests/request.component.ts @@ -1,7 +1,6 @@ import { Component } from '@angular/core'; @Component({ - selector: 'ombi', templateUrl: './request.component.html' }) export class RequestComponent { diff --git a/src/Ombi/ClientApp/app/requests/tvrequests.component.html b/src/Ombi/ClientApp/app/requests/tvrequests.component.html index 4d98b38d2..ac248faef 100644 --- a/src/Ombi/ClientApp/app/requests/tvrequests.component.html +++ b/src/Ombi/ClientApp/app/requests/tvrequests.component.html @@ -78,29 +78,8 @@ - -
- -
-
-
- Requested By: {{user}} -
-
- Seasons Requested: {{s.seasonNumber}} -
-
- Request status: - Available - Processing Request - Request Denied - - Pending Approval - -
-
- -
+ +
@@ -216,12 +195,36 @@