1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Fixed: Improved message when a conflicting slug is added

This commit is contained in:
Mark McDowall 2017-05-17 21:42:57 -07:00
parent cf7ce9804f
commit edf549d0fd
No known key found for this signature in database
GPG Key ID: D4CEFA9A718052E0

View File

@ -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;
}
}
}