Files
ersatztv/ErsatzTV/Validators/ChannelEditViewModelValidator.cs
T
Jason DoveandGitHub 7e30444857 dependencies and code cleanup (#2117)
* fix validation in new form layout

* pin mediatr to last oss version

* update dependencies

* cleanup code in core

* cleanup code in ffmpeg

* cleanup code in infra

* cleanup code in scanner

* cleanup code in application

* cleanup main code

* cleanup test code

* solution-wide code cleanup
2025-07-06 15:56:17 +00:00

43 lines
1.3 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");
});
}
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);
};
}