Files
ersatztv/ErsatzTV/Validators/ChannelEditViewModelValidator.cs
T
Jason DoveandGitHub 5d081ceeff fix editorconfig and run code cleanup (#2324)
* fix formatting rules

* reformat ersatztv

* reformat ersatztv.application

* reformat ersatztv.core

* refactor ersatztv.core.tests

* reformat ersatztv.ffmpeg

* reformat ersatztv.ffmpeg.tests

* reformat ersatztv.infrastructure

* cleanup infra mysql

* cleanup infra sqlite

* cleanup infra tests

* cleanup ersatztv.scanner

* cleanup ersatztv.scanner.tests

* sln cleanup

* update dependencies
2025-08-16 14:44:48 +00:00

52 lines
1.6 KiB
C#

using ErsatzTV.Core.Domain;
using ErsatzTV.ViewModels;
using FluentValidation;
using FluentValidation.Results;
namespace ErsatzTV.Validators;
public class ChannelEditViewModelValidator : AbstractValidator<ChannelEditViewModel>
{
public ChannelEditViewModelValidator()
{
RuleFor(x => x.Number).Matches(Channel.NumberValidator)
.WithMessage("Invalid channel number; two decimals are allowed for subchannels");
RuleFor(x => x.Name).NotEmpty();
RuleFor(x => x.Group).NotEmpty();
RuleFor(x => x.FFmpegProfileId).GreaterThan(0);
When(
x => !string.IsNullOrWhiteSpace(x.ExternalLogoUrl),
() =>
{
RuleFor(x => x.ExternalLogoUrl)
.Must(Artwork.IsExternalUrl)
.WithMessage("External logo url is invalid");
});
When(
x => !x.IsEnabled,
() =>
{
RuleFor(x => x.ShowInEpg)
.Must(x => !x)
.WithMessage("Disabled channels cannot be shown in EPG");
});
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
ValidationResult result = await ValidateAsync(
ValidationContext<ChannelEditViewModel>.CreateWithOptions(
(ChannelEditViewModel)model,
x => x.IncludeProperties(propertyName)));
if (result.IsValid)
{
return [];
}
return result.Errors.Select(e => e.ErrorMessage);
};
}