This commit is contained in:
tidusjar 2017-05-13 23:21:50 +01:00
commit a278917dcd
8 changed files with 157 additions and 139 deletions

View file

@ -4,6 +4,7 @@ using System.Globalization;
using System.Linq;
using System.Security.Principal;
using System.Threading.Tasks;
using AutoMapper;
using Hangfire;
using Ombi.Api.TvMaze;
using Ombi.Core.Models.Requests;
@ -17,13 +18,15 @@ namespace Ombi.Core.Engine
{
public class TvRequestEngine : BaseMediaEngine, ITvRequestEngine
{
public TvRequestEngine(ITvMazeApi tvApi, IRequestServiceMain requestService, IPrincipal user, INotificationService notificationService) : base(user, requestService)
public TvRequestEngine(ITvMazeApi tvApi, IRequestServiceMain requestService, IPrincipal user, INotificationService notificationService, IMapper map) : base(user, requestService)
{
TvApi = tvApi;
NotificationService = notificationService;
Mapper = map;
}
private INotificationService NotificationService { get; }
private ITvMazeApi TvApi { get; }
private IMapper Mapper { get; }
public async Task<RequestEngineResult> RequestTvShow(SearchTvShowViewModel tv)
{
@ -166,6 +169,16 @@ namespace Ombi.Core.Engine
newRequest.SeasonRequests = episodeDifference;
}
if (!existingRequest.HasChildRequests)
{
// So this is the first child request, we will want to convert the original request to a child
var originalRequest = Mapper.Map<TvRequestModel>(existingRequest);
existingRequest.ChildRequests.Add(originalRequest);
existingRequest.RequestedUsers.Clear();
existingRequest.Approved = false;
existingRequest.Available = false;
}
existingRequest.ChildRequests.Add(newRequest);
TvRequestService.UpdateRequest(existingRequest);