@ -32,14 +32,13 @@ namespace Ombi.Core.Engine
{
{
public TvRequestEngine ( ITvMazeApi tvApi , IMovieDbApi movApi , IRequestServiceMain requestService , IPrincipal user ,
public TvRequestEngine ( ITvMazeApi tvApi , IMovieDbApi movApi , IRequestServiceMain requestService , IPrincipal user ,
INotificationHelper helper , IRuleEvaluator rule , OmbiUserManager manager ,
INotificationHelper helper , IRuleEvaluator rule , OmbiUserManager manager ,
ITvSender sender , I AuditRepository audit , I Repository< RequestLog > rl , ISettingsService < OmbiSettings > settings , ICacheService cache ,
ITvSender sender , I Repository< RequestLog > rl , ISettingsService < OmbiSettings > settings , ICacheService cache ,
IRepository < RequestSubscription > sub ) : base ( user , requestService , rule , manager , cache , settings , sub )
IRepository < RequestSubscription > sub ) : base ( user , requestService , rule , manager , cache , settings , sub )
{
{
TvApi = tvApi ;
TvApi = tvApi ;
MovieDbApi = movApi ;
MovieDbApi = movApi ;
NotificationHelper = helper ;
NotificationHelper = helper ;
TvSender = sender ;
TvSender = sender ;
Audit = audit ;
_requestLog = rl ;
_requestLog = rl ;
}
}
@ -47,7 +46,6 @@ namespace Ombi.Core.Engine
private ITvMazeApi TvApi { get ; }
private ITvMazeApi TvApi { get ; }
private IMovieDbApi MovieDbApi { get ; }
private IMovieDbApi MovieDbApi { get ; }
private ITvSender TvSender { get ; }
private ITvSender TvSender { get ; }
private IAuditRepository Audit { get ; }
private readonly IRepository < RequestLog > _requestLog ;
private readonly IRepository < RequestLog > _requestLog ;
public async Task < RequestEngineResult > RequestTvShow ( TvRequestViewModel tv )
public async Task < RequestEngineResult > RequestTvShow ( TvRequestViewModel tv )
@ -85,8 +83,6 @@ namespace Ombi.Core.Engine
}
}
}
}
await Audit . Record ( AuditType . Added , AuditArea . TvRequest , $"Added Request {tvBuilder.ChildRequest.Title}" , Username ) ;
var existingRequest = await TvRepository . Get ( ) . FirstOrDefaultAsync ( x = > x . TvDbId = = tv . TvDbId ) ;
var existingRequest = await TvRepository . Get ( ) . FirstOrDefaultAsync ( x = > x . TvDbId = = tv . TvDbId ) ;
if ( existingRequest ! = null )
if ( existingRequest ! = null )
{
{
@ -408,7 +404,6 @@ namespace Ombi.Core.Engine
public async Task < TvRequests > UpdateTvRequest ( TvRequests request )
public async Task < TvRequests > UpdateTvRequest ( TvRequests request )
{
{
await Audit . Record ( AuditType . Updated , AuditArea . TvRequest , $"Updated Request {request.Title}" , Username ) ;
var allRequests = TvRepository . Get ( ) ;
var allRequests = TvRepository . Get ( ) ;
var results = await allRequests . FirstOrDefaultAsync ( x = > x . Id = = request . Id ) ;
var results = await allRequests . FirstOrDefaultAsync ( x = > x . Id = = request . Id ) ;
@ -451,7 +446,6 @@ namespace Ombi.Core.Engine
if ( request . Approved )
if ( request . Approved )
{
{
NotificationHelper . Notify ( request , NotificationType . RequestApproved ) ;
NotificationHelper . Notify ( request , NotificationType . RequestApproved ) ;
await Audit . Record ( AuditType . Approved , AuditArea . TvRequest , $"Approved Request {request.Title}" , Username ) ;
// Autosend
// Autosend
await TvSender . Send ( request ) ;
await TvSender . Send ( request ) ;
}
}
@ -483,9 +477,7 @@ namespace Ombi.Core.Engine
public async Task < ChildRequests > UpdateChildRequest ( ChildRequests request )
public async Task < ChildRequests > UpdateChildRequest ( ChildRequests request )
{
{
await Audit . Record ( AuditType . Updated , AuditArea . TvRequest , $"Updated Request {request.Title}" , Username ) ;
await TvRepository . UpdateChild ( request ) ;
await TvRepository . UpdateChild ( request ) ;
return request ;
return request ;
}
}
@ -503,16 +495,14 @@ namespace Ombi.Core.Engine
// Delete the parent
// Delete the parent
TvRepository . Db . TvRequests . Remove ( parent ) ;
TvRepository . Db . TvRequests . Remove ( parent ) ;
}
}
await Audit . Record ( AuditType . Deleted , AuditArea . TvRequest , $"Deleting Request {request.Title}" , Username ) ;
await TvRepository . Db . SaveChangesAsync ( ) ;
await TvRepository . Db . SaveChangesAsync ( ) ;
}
}
public async Task RemoveTvRequest ( int requestId )
public async Task RemoveTvRequest ( int requestId )
{
{
var request = await TvRepository . Get ( ) . FirstOrDefaultAsync ( x = > x . Id = = requestId ) ;
var request = await TvRepository . Get ( ) . FirstOrDefaultAsync ( x = > x . Id = = requestId ) ;
await Audit . Record ( AuditType . Deleted , AuditArea . TvRequest , $"Deleting Request {request.Title}" , Username ) ;
await TvRepository . Delete ( request ) ;
await TvRepository . Delete ( request ) ;
}
}
public async Task < bool > UserHasRequest ( string userId )
public async Task < bool > UserHasRequest ( string userId )