diff --git a/src/NzbDrone.Api/Series/SeriesModule.cs b/src/NzbDrone.Api/Series/SeriesModule.cs
index 72799e9ae..b52e41a4d 100644
--- a/src/NzbDrone.Api/Series/SeriesModule.cs
+++ b/src/NzbDrone.Api/Series/SeriesModule.cs
@@ -10,11 +10,11 @@ using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.SeriesStats;
using NzbDrone.Core.Tv;
-using NzbDrone.Api.Validation;
using NzbDrone.Api.Mapping;
using NzbDrone.Core.Tv.Events;
using NzbDrone.Core.Validation.Paths;
using NzbDrone.Core.DataAugmentation.Scene;
+using NzbDrone.Core.Validation;
using NzbDrone.SignalR;
namespace NzbDrone.Api.Series
@@ -43,7 +43,8 @@ namespace NzbDrone.Api.Series
SeriesPathValidator seriesPathValidator,
SeriesExistsValidator seriesExistsValidator,
DroneFactoryValidator droneFactoryValidator,
- SeriesAncestorValidator seriesAncestorValidator
+ SeriesAncestorValidator seriesAncestorValidator,
+ ProfileExistsValidator profileExistsValidator
)
: base(signalRBroadcaster)
{
@@ -59,7 +60,7 @@ namespace NzbDrone.Api.Series
UpdateResource = UpdateSeries;
DeleteResource = DeleteSeries;
- SharedValidator.RuleFor(s => s.ProfileId).ValidId();
+ Validation.RuleBuilderExtensions.ValidId(SharedValidator.RuleFor(s => s.ProfileId));
SharedValidator.RuleFor(s => s.Path)
.Cascade(CascadeMode.StopOnFirstFailure)
@@ -70,6 +71,8 @@ namespace NzbDrone.Api.Series
.SetValidator(seriesAncestorValidator)
.When(s => !s.Path.IsNullOrWhiteSpace());
+ SharedValidator.RuleFor(s => s.ProfileId).SetValidator(profileExistsValidator);
+
PostValidator.RuleFor(s => s.Path).IsValidPath().When(s => s.RootFolderPath.IsNullOrWhiteSpace());
PostValidator.RuleFor(s => s.RootFolderPath).IsValidPath().When(s => s.Path.IsNullOrWhiteSpace());
PostValidator.RuleFor(s => s.Title).NotEmpty();
diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj
index 0ede6fc89..edd3a2103 100644
--- a/src/NzbDrone.Core/NzbDrone.Core.csproj
+++ b/src/NzbDrone.Core/NzbDrone.Core.csproj
@@ -1004,6 +1004,7 @@
+
diff --git a/src/NzbDrone.Core/Profiles/ProfileRepository.cs b/src/NzbDrone.Core/Profiles/ProfileRepository.cs
index 526ab0801..4e071a0cf 100644
--- a/src/NzbDrone.Core/Profiles/ProfileRepository.cs
+++ b/src/NzbDrone.Core/Profiles/ProfileRepository.cs
@@ -5,7 +5,7 @@ namespace NzbDrone.Core.Profiles
{
public interface IProfileRepository : IBasicRepository
{
-
+ bool Exists(int id);
}
public class ProfileRepository : BasicRepository, IProfileRepository
@@ -14,5 +14,10 @@ namespace NzbDrone.Core.Profiles
: base(database, eventAggregator)
{
}
+
+ public bool Exists(int id)
+ {
+ return DataMapper.Query().Where(p => p.Id == id).GetRowCount() == 1;
+ }
}
}
diff --git a/src/NzbDrone.Core/Profiles/ProfileService.cs b/src/NzbDrone.Core/Profiles/ProfileService.cs
index dcb743e3f..e439b1a43 100644
--- a/src/NzbDrone.Core/Profiles/ProfileService.cs
+++ b/src/NzbDrone.Core/Profiles/ProfileService.cs
@@ -16,6 +16,7 @@ namespace NzbDrone.Core.Profiles
void Delete(int id);
List All();
Profile Get(int id);
+ bool Exists(int id);
}
public class ProfileService : IProfileService, IHandle
@@ -61,6 +62,11 @@ namespace NzbDrone.Core.Profiles
return _profileRepository.Get(id);
}
+ public bool Exists(int id)
+ {
+ return _profileRepository.Exists(id);
+ }
+
private Profile AddDefaultProfile(string name, Quality cutoff, params Quality[] allowed)
{
var items = Quality.DefaultQualityDefinitions
diff --git a/src/NzbDrone.Core/Validation/ProfileExistsValidator.cs b/src/NzbDrone.Core/Validation/ProfileExistsValidator.cs
new file mode 100644
index 000000000..e7ff62b67
--- /dev/null
+++ b/src/NzbDrone.Core/Validation/ProfileExistsValidator.cs
@@ -0,0 +1,23 @@
+using FluentValidation.Validators;
+using NzbDrone.Core.Profiles;
+
+namespace NzbDrone.Core.Validation
+{
+ public class ProfileExistsValidator : PropertyValidator
+ {
+ private readonly IProfileService _profileService;
+
+ public ProfileExistsValidator(IProfileService profileService)
+ : base("Profile does not exist")
+ {
+ _profileService = profileService;
+ }
+
+ protected override bool IsValid(PropertyValidatorContext context)
+ {
+ if (context.PropertyValue == null) return true;
+
+ return _profileService.Exists((int)context.PropertyValue);
+ }
+ }
+}
\ No newline at end of file