@ -1,14 +1,13 @@
using System ;
using System ;
using System.Collections.Generic ;
using System.Collections.Generic ;
using System.Globalization ;
using System.Linq ;
using System.Linq ;
using AutoMapper ;
using FluentValidation ;
using FluentValidation ;
using NzbDrone.Api.Extensions ;
using NzbDrone.Api.Extensions ;
using NzbDrone.Common ;
using NzbDrone.Common ;
using NzbDrone.Common ;
using NzbDrone.Core.SeriesStats ;
using NzbDrone.Core.SeriesStats ;
using NzbDrone.Api.Mapping ;
using NzbDrone.Core.Tv ;
using NzbDrone.Core.Tv ;
using NzbDrone.Core.Model ;
using NzbDrone.Api.Validation ;
using NzbDrone.Api.Validation ;
namespace NzbDrone.Api.Series
namespace NzbDrone.Api.Series
@ -43,7 +42,8 @@ namespace NzbDrone.Api.Series
{
{
var series = _seriesService . GetAllSeries ( ) . ToList ( ) ;
var series = _seriesService . GetAllSeries ( ) . ToList ( ) ;
var seriesStats = _seriesStatisticsService . SeriesStatistics ( ) ;
var seriesStats = _seriesStatisticsService . SeriesStatistics ( ) ;
var seriesModels = Mapper . Map < List < Core . Tv . Series > , List < SeriesResource > > ( series ) ;
var seriesModels = series . InjectTo < List < SeriesResource > > ( ) ;
foreach ( var s in seriesModels )
foreach ( var s in seriesModels )
{
{
@ -52,7 +52,7 @@ namespace NzbDrone.Api.Series
s . EpisodeCount = stats . EpisodeCount ;
s . EpisodeCount = stats . EpisodeCount ;
s . EpisodeFileCount = stats . EpisodeFileCount ;
s . EpisodeFileCount = stats . EpisodeFileCount ;
s . NumberOf Seasons = stats . NumberOfSeasons ;
s . SeasonsCount = stats . NumberOfSeasons ;
s . NextAiring = stats . NextAiring ;
s . NextAiring = stats . NextAiring ;
}
}
@ -62,8 +62,7 @@ namespace NzbDrone.Api.Series
private SeriesResource GetSeries ( int id )
private SeriesResource GetSeries ( int id )
{
{
var series = _seriesService . GetSeries ( id ) ;
var series = _seriesService . GetSeries ( id ) ;
var seriesModels = Mapper . Map < Core . Tv . Series , SeriesResource > ( series ) ;
return series . InjectTo < SeriesResource > ( ) ;
return seriesModels ;
}
}
private SeriesResource AddSeries ( SeriesResource seriesResource )
private SeriesResource AddSeries ( SeriesResource seriesResource )
@ -74,9 +73,9 @@ namespace NzbDrone.Api.Series
//Todo: We need to create the folder if the user is adding a new series
//Todo: We need to create the folder if the user is adding a new series
//(we can just create the folder and it won't blow up if it already exists)
//(we can just create the folder and it won't blow up if it already exists)
//We also need to remove any special characters from the filename before attempting to create it
//We also need to remove any special characters from the filename before attempting to create it
var series = Mapper. Map < SeriesResource , Core . Tv . Series > ( seriesResource ) ;
var series = seriesResource. InjectTo < Core . Tv . Series > ( ) ;
_seriesService . AddSeries ( series ) ;
_seriesService . AddSeries ( series ) ;
return Mapper. Map < Core . Tv . Series , SeriesResource > ( series ) ;
return series. InjectTo < SeriesResource > ( ) ;
}
}
private SeriesResource UpdateSeries ( SeriesResource seriesResource )
private SeriesResource UpdateSeries ( SeriesResource seriesResource )
@ -91,17 +90,11 @@ namespace NzbDrone.Api.Series
series . RootFolderId = seriesResource . RootFolderId ;
series . RootFolderId = seriesResource . RootFolderId ;
series . FolderName = seriesResource . FolderName ;
series . FolderName = seriesResource . FolderName ;
series . BacklogSetting = ( BacklogSettingType ) seriesResource . BacklogSetting ;
series . BacklogSetting = seriesResource . BacklogSetting ;
if ( ! String . IsNullOrWhiteSpace ( seriesResource . CustomStartDate ) )
series . CustomStartDate = DateTime . Parse ( seriesResource . CustomStartDate , null , DateTimeStyles . RoundtripKind ) ;
else
series . CustomStartDate = null ;
_seriesService . UpdateSeries ( series ) ;
_seriesService . UpdateSeries ( series ) ;
return Mapper. Map < Core . Tv . Series , SeriesResource > ( series ) ;
return series . InjectTo < SeriesResource > ( ) ;
}
}
private void DeleteSeries ( int id )
private void DeleteSeries ( int id )
@ -111,23 +104,4 @@ namespace NzbDrone.Api.Series
}
}
}
}
public class SeriesValidator : AbstractValidator < Core . Tv . Series >
}
{
private readonly DiskProvider _diskProvider ;
public SeriesValidator ( DiskProvider diskProvider )
{
_diskProvider = diskProvider ;
}
public SeriesValidator ( )
{
RuleSet ( "POST" , ( ) = >
{
RuleFor ( s = > s . Id ) . GreaterThan ( 0 ) ;
RuleFor ( s = > s . Path ) . NotEmpty ( ) . Must ( _diskProvider . FolderExists ) ;
RuleFor ( s = > s . QualityProfileId ) . GreaterThan ( 0 ) ;
} ) ;
}
}
}