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.
Lidarr/src/NzbDrone.Core/Music/ArtistSlugValidator.cs

30 lines
913 B

using FluentValidation.Validators;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Music
{
public class ArtistSlugValidator : PropertyValidator
{
private readonly IArtistService _artistService;
public ArtistSlugValidator(IArtistService artistService)
: base("Title slug is in use by another artist with a similar name")
{
_artistService = artistService;
}
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null) return true;
dynamic instance = context.ParentContext.InstanceToValidate;
var instanceId = (int)instance.Id;
return !_artistService.GetAllArtists().Exists(s => s.ArtistSlug.Equals(context.PropertyValue.ToString()) && s.Id != instanceId);
}
}
}