mirror of
https://github.com/Radarr/Radarr
synced 2025-02-22 14:21:14 +00:00
parent
e923b2fc6c
commit
8a84975954
1 changed files with 26 additions and 1 deletions
|
@ -1,7 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using Radarr.Http;
|
||||
using Radarr.Http.REST;
|
||||
|
@ -24,7 +27,29 @@ public CustomFormatController(ICustomFormatService formatService,
|
|||
SharedValidator.RuleFor(c => c.Name).NotEmpty();
|
||||
SharedValidator.RuleFor(c => c.Name)
|
||||
.Must((v, c) => !_formatService.All().Any(f => f.Name == c && f.Id != v.Id)).WithMessage("Must be unique.");
|
||||
SharedValidator.RuleFor(c => c.Specifications).NotEmpty();
|
||||
SharedValidator.RuleFor(c => c).Custom((customFormat, context) =>
|
||||
{
|
||||
if (!customFormat.Specifications.Any())
|
||||
{
|
||||
context.AddFailure("Must contain at least one Condition");
|
||||
}
|
||||
|
||||
if (customFormat.Specifications.Any(s => s.Name.IsNullOrWhiteSpace()))
|
||||
{
|
||||
context.AddFailure("Condition name(s) cannot be empty or consist of only spaces");
|
||||
}
|
||||
|
||||
foreach (var specification in customFormat.Specifications)
|
||||
{
|
||||
foreach (var field in specification.Fields.Where(f => (FieldType)Enum.Parse(typeof(FieldType), f.Type, true) == FieldType.Textbox))
|
||||
{
|
||||
if (specification.Name.IsNotNullOrWhiteSpace() && ((string)field.Value).IsNullOrWhiteSpace())
|
||||
{
|
||||
context.AddFailure(string.Format("'{0}' of condition '{1}' cannot be empty or consist of only spaces", field.Label, specification.Name));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected override CustomFormatResource GetResourceById(int id)
|
||||
|
|
Loading…
Reference in a new issue