mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Fixed: Improved message when a conflicting slug is added
This commit is contained in:
parent
cf7ce9804f
commit
edf549d0fd
@ -9,7 +9,7 @@ public class SeriesTitleSlugValidator : PropertyValidator
|
||||
private readonly ISeriesService _seriesService;
|
||||
|
||||
public SeriesTitleSlugValidator(ISeriesService seriesService)
|
||||
: base("Title slug is in use by another series with a similar name")
|
||||
: base("Title slug '{slug}' is in use by series '{seriesTitle}'")
|
||||
{
|
||||
_seriesService = seriesService;
|
||||
}
|
||||
@ -21,10 +21,22 @@ protected override bool IsValid(PropertyValidatorContext context)
|
||||
|
||||
dynamic instance = context.ParentContext.InstanceToValidate;
|
||||
var instanceId = (int)instance.Id;
|
||||
var slug = context.PropertyValue.ToString();
|
||||
|
||||
return !_seriesService.GetAllSeries().Where(s => s.TitleSlug.IsNotNullOrWhiteSpace())
|
||||
.ToList()
|
||||
.Exists(s => s.TitleSlug.Equals(context.PropertyValue.ToString()) && s.Id != instanceId);
|
||||
var conflictingSeries = _seriesService.GetAllSeries()
|
||||
.FirstOrDefault(s => s.TitleSlug.IsNotNullOrWhiteSpace() &&
|
||||
s.TitleSlug.Equals(context.PropertyValue.ToString()) &&
|
||||
s.Id != instanceId);
|
||||
|
||||
if (conflictingSeries == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
context.MessageFormatter.AppendArgument("slug", slug);
|
||||
context.MessageFormatter.AppendArgument("seriesTitle", conflictingSeries.Title);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user