You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.1 KiB
35 lines
1.1 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using FluentValidation.Validators;
|
|
using NzbDrone.Common;
|
|
using NzbDrone.Common.Extensions;
|
|
using Omu.ValueInjecter;
|
|
|
|
namespace NzbDrone.Core.Profiles.Delay
|
|
{
|
|
public class DelayProfileTagInUseValidator : PropertyValidator
|
|
{
|
|
private readonly IDelayProfileService _delayProfileService;
|
|
|
|
public DelayProfileTagInUseValidator(IDelayProfileService delayProfileService)
|
|
: base("One or more tags is used in another profile")
|
|
{
|
|
_delayProfileService = delayProfileService;
|
|
}
|
|
|
|
protected override bool IsValid(PropertyValidatorContext context)
|
|
{
|
|
if (context.PropertyValue == null) return true;
|
|
|
|
var delayProfile = new DelayProfile();
|
|
delayProfile.InjectFrom(context.ParentContext.InstanceToValidate);
|
|
|
|
var collection = context.PropertyValue as HashSet<int>;
|
|
|
|
if (collection == null || collection.Empty()) return true;
|
|
|
|
return _delayProfileService.All().None(d => d.Id != delayProfile.Id && d.Tags.Intersect(collection).Any());
|
|
}
|
|
}
|
|
}
|