From edf549d0fd331196d20dbe7378c24f83a69ca612 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 17 May 2017 21:42:57 -0700 Subject: [PATCH] Fixed: Improved message when a conflicting slug is added --- .../Tv/SeriesTitleSlugValidator.cs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/NzbDrone.Core/Tv/SeriesTitleSlugValidator.cs b/src/NzbDrone.Core/Tv/SeriesTitleSlugValidator.cs index ce3d7ecbf..fe329a698 100644 --- a/src/NzbDrone.Core/Tv/SeriesTitleSlugValidator.cs +++ b/src/NzbDrone.Core/Tv/SeriesTitleSlugValidator.cs @@ -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; } } }