Fixed: Improved message when a conflicting slug is added

pull/94/head
Qstick 7 years ago
parent f8f988a083
commit d7ef6cc88b

@ -12,7 +12,7 @@ namespace NzbDrone.Core.Music
private readonly IArtistService _artistService; private readonly IArtistService _artistService;
public ArtistSlugValidator(IArtistService artistService) public ArtistSlugValidator(IArtistService artistService)
: base("Title slug is in use by another artist with a similar name") : base("Name slug '{slug}' is in use by artist '{artistName}'")
{ {
_artistService = artistService; _artistService = artistService;
} }
@ -23,10 +23,22 @@ namespace NzbDrone.Core.Music
dynamic instance = context.ParentContext.InstanceToValidate; dynamic instance = context.ParentContext.InstanceToValidate;
var instanceId = (int)instance.Id; var instanceId = (int)instance.Id;
var slug = context.PropertyValue.ToString();
return !_artistService.GetAllArtists().Where(s => s.NameSlug.IsNotNullOrWhiteSpace()) var conflictingArtist = _artistService.GetAllArtists()
.ToList() .FirstOrDefault(s => s.NameSlug.IsNotNullOrWhiteSpace() &&
.Exists(s => s.NameSlug.Equals(context.PropertyValue.ToString()) && s.Id != instanceId); s.NameSlug.Equals(context.PropertyValue.ToString()) &&
s.Id != instanceId);
if (conflictingArtist == null)
{
return true;
}
context.MessageFormatter.AppendArgument("slug", slug);
context.MessageFormatter.AppendArgument("artistName", conflictingArtist.Name);
return false;
} }
} }
} }

Loading…
Cancel
Save