You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/src/NzbDrone.Core/Validation/Paths/ArtistExistsValidator.cs

30 lines
838 B

using FluentValidation.Validators;
using NzbDrone.Core.Music;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Validation.Paths
{
public class ArtistExistsValidator : PropertyValidator
{
private readonly IArtistService _artistService;
public ArtistExistsValidator(IArtistService artistService)
: base("This artist has already been added")
{
_artistService = artistService;
}
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null) return true;
var itunesId = Convert.ToInt32(context.PropertyValue.ToString());
return (!_artistService.GetAllArtists().Exists(s => s.ItunesId == itunesId));
}
}
}