Files
ersatztv/ErsatzTV/Validators/PlayoutEditViewModelValidator.cs
T
Jason DoveandGitHub 53f281ce32 add xmltv block behavior setting (#2336)
* replace playout externaljsonfile and templatefile with schedulefile

* add scripted schedule-based playout

* wip - not functional yet

* temp disable scripted playout creation

* allow fast-forwarding block playouts

* add xmltv block behavior setting
2025-08-23 20:16:12 +00:00

31 lines
1.0 KiB
C#

using ErsatzTV.ViewModels;
using FluentValidation;
using FluentValidation.Results;
namespace ErsatzTV.Validators;
public class PlayoutEditViewModelValidator : AbstractValidator<PlayoutEditViewModel>
{
public PlayoutEditViewModelValidator()
{
RuleFor(p => p.Channel).NotNull();
RuleFor(p => p.ProgramSchedule).NotNull().When(p => string.IsNullOrWhiteSpace(p.Kind));
RuleFor(p => p.ScheduleFile).NotNull().When(p =>
p.Kind is PlayoutKind.ExternalJson or PlayoutKind.Sequential or PlayoutKind.Scripted);
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
ValidationResult result = await ValidateAsync(
ValidationContext<PlayoutEditViewModel>.CreateWithOptions(
(PlayoutEditViewModel)model,
x => x.IncludeProperties(propertyName)));
if (result.IsValid)
{
return [];
}
return result.Errors.Select(e => e.ErrorMessage);
};
}