mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-21 13:37:19 +00:00
Fixed: Improved message when a conflicting slug is added
This commit is contained in:
parent
f8f988a083
commit
d7ef6cc88b
1 changed files with 16 additions and 4 deletions
|
@ -12,7 +12,7 @@ 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")
|
||||
: base("Name slug '{slug}' is in use by artist '{artistName}'")
|
||||
{
|
||||
_artistService = artistService;
|
||||
}
|
||||
|
@ -23,10 +23,22 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||
|
||||
dynamic instance = context.ParentContext.InstanceToValidate;
|
||||
var instanceId = (int)instance.Id;
|
||||
var slug = context.PropertyValue.ToString();
|
||||
|
||||
return !_artistService.GetAllArtists().Where(s => s.NameSlug.IsNotNullOrWhiteSpace())
|
||||
.ToList()
|
||||
.Exists(s => s.NameSlug.Equals(context.PropertyValue.ToString()) && s.Id != instanceId);
|
||||
var conflictingArtist = _artistService.GetAllArtists()
|
||||
.FirstOrDefault(s => s.NameSlug.IsNotNullOrWhiteSpace() &&
|
||||
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…
Reference in a new issue