@ -30,6 +30,8 @@ using System.Linq;
using Mono.Data.Sqlite ;
using RequestPlex.Api ;
using RequestPlex.Api.Models.Tv ;
using RequestPlex.Helpers ;
using RequestPlex.Store ;
namespace RequestPlex.Core
@ -37,7 +39,7 @@ namespace RequestPlex.Core
public class SettingsService
{
public SettingsModel GetSettings ( )
public SettingsModel GetSettings ( ICacheProvider cache )
{
var db = new DbConfiguration ( new SqliteFactory ( ) ) ;
var repo = new GenericRepository < SettingsModel > ( db ) ;
@ -46,18 +48,20 @@ namespace RequestPlex.Core
return settings ;
}
private ICacheProvider Cache { get ; set ; }
public void AddRequest ( int tmdbi d, RequestType type )
public void AddRequest ( int providerI d, RequestType type )
{
var api = new TheMovieDbApi ( ) ;
var model = new RequestedModel ( ) ;
if ( type = = RequestType . Movie )
{
var movieInfo = api . GetMovieInformation ( tmdbid ) . Result ;
var movieApi = new TheMovieDbApi ( ) ;
var movieInfo = movieApi . GetMovieInformation ( providerId ) . Result ;
model = new RequestedModel
{
Tmdbi d = movieInfo . Id ,
ProviderI d = movieInfo . Id ,
Type = type ,
Overview = movieInfo . Overview ,
ImdbId = movieInfo . ImdbId ,
@ -71,17 +75,23 @@ namespace RequestPlex.Core
}
else
{
var showInfo = api . GetTvShowInformation ( tmdbid ) . Result ;
var tvApi = new TheTvDbApi ( ) ;
var token = GetAuthToken ( tvApi ) ;
var showInfo = tvApi . GetInformation ( providerId , token ) ;
DateTime firstAir ;
DateTime . TryParse ( showInfo . firstAired , out firstAir ) ;
model = new RequestedModel
{
Tmdbid = showInfo . Id ,
ProviderId = showInfo . i d,
Type = type ,
Overview = showInfo . Overview ,
PosterPath = "http://image.tmdb.org/t/p/w150/" + showInfo . PosterPath,
Title = showInfo . Name,
ReleaseDate = showIn fo. F irstAirDate ? ? DateTime . MinValue ,
Status = showInfo . S tatus,
Overview = showInfo . o verview,
PosterPath = "http://image.tmdb.org/t/p/w150/" + showInfo . banner, // This is incorrect
Title = showInfo . series Name,
ReleaseDate = firstAir,
Status = showInfo . s tatus,
RequestedDate = DateTime . Now ,
Approved = false
} ;
@ -92,21 +102,25 @@ namespace RequestPlex.Core
repo . Insert ( model ) ;
}
public bool CheckRequest ( int tmdbi d)
public bool CheckRequest ( int providerI d)
{
var db = new DbConfiguration ( new SqliteFactory ( ) ) ;
var repo = new GenericRepository < RequestedModel > ( db ) ;
return repo . GetAll ( ) . Any ( x = > x . Tmdbid = = tmdbi d) ;
return repo . GetAll ( ) . Any ( x = > x . ProviderId = = providerI d) ;
}
public void DeleteRequest ( int tmdbId )
{
var db = new DbConfiguration ( new SqliteFactory ( ) ) ;
var repo = new GenericRepository < RequestedModel > ( db ) ;
var entity = repo . GetAll ( ) . FirstOrDefault ( x = > x . Tmdbi d = = tmdbId ) ;
var entity = repo . GetAll ( ) . FirstOrDefault ( x = > x . ProviderI d = = tmdbId ) ;
repo . Delete ( entity ) ;
}
private string GetAuthToken ( TheTvDbApi api )
{
return Cache . GetOrSet ( CacheKeys . TvDbToken , api . Authenticate , 50 ) ;
}
}
}