From 4e6f49b9109e1775fa51685918ba94705fd399a0 Mon Sep 17 00:00:00 2001 From: Dominic Villemure Date: Sun, 18 Aug 2024 12:04:07 -0400 Subject: [PATCH] Fixed color validator ( they are selected one by one in the UI ) --- .../Contents/Handlers/ChangeColors.cs | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/Web/Features/Contents/Handlers/ChangeColors.cs b/src/Web/Features/Contents/Handlers/ChangeColors.cs index 40b45fe..9e2f1c9 100644 --- a/src/Web/Features/Contents/Handlers/ChangeColors.cs +++ b/src/Web/Features/Contents/Handlers/ChangeColors.cs @@ -16,25 +16,34 @@ public sealed class ChangeColorsRequestValidator { public ChangeColorsRequestValidator() { - RuleFor(x => x.BannerTop) - .MinimumLength(4).WithMessage("The minimum value should be in the format #444") - .MaximumLength(9).WithMessage("The maximum value should be in the format #11223344") - .Must(x => x.StartsWith('#')).WithMessage("The format should be a valid html color and start with #"); - - RuleFor(x => x.BannerBottom) - .MinimumLength(4).WithMessage("The minimum value should be in the format #444") - .MaximumLength(9).WithMessage("The maximum value should be in the format #11223344") - .Must(x => x.StartsWith('#')).WithMessage("The format should be a valid html color and start with #"); - - RuleFor(x => x.Accent) - .MinimumLength(4).WithMessage("The minimum value should be in the format #444") - .MaximumLength(9).WithMessage("The maximum value should be in the format #11223344") - .Must(x => x.StartsWith('#')).WithMessage("The format should be a valid html color and start with #"); - - RuleFor(x => x.Menu) - .MinimumLength(4).WithMessage("The minimum value should be in the format #444") - .MaximumLength(9).WithMessage("The maximum value should be in the format #11223344") - .Must(x => x.StartsWith('#')).WithMessage("The format should be a valid html color and start with #"); + When(x => x.BannerTop is not null, () => + { + RuleFor(x => x.BannerTop) + .MinimumLength(4).WithMessage("The minimum value should be in the format #444") + .MaximumLength(9).WithMessage("The maximum value should be in the format #11223344") + .Must(x => x.StartsWith('#')).WithMessage("The format should be a valid html color and start with #"); + }); + When(x => x.BannerBottom is not null, () => + { + RuleFor(x => x.BannerBottom) + .MinimumLength(4).WithMessage("The minimum value should be in the format #444") + .MaximumLength(9).WithMessage("The maximum value should be in the format #11223344") + .Must(x => x.StartsWith('#')).WithMessage("The format should be a valid html color and start with #"); + }); + When(x => x.Accent is not null, () => + { + RuleFor(x => x.Accent) + .MinimumLength(4).WithMessage("The minimum value should be in the format #444") + .MaximumLength(9).WithMessage("The maximum value should be in the format #11223344") + .Must(x => x.StartsWith('#')).WithMessage("The format should be a valid html color and start with #"); + }); + When(x => x.Menu is not null, () => + { + RuleFor(x => x.Menu) + .MinimumLength(4).WithMessage("The minimum value should be in the format #444") + .MaximumLength(9).WithMessage("The maximum value should be in the format #11223344") + .Must(x => x.StartsWith('#')).WithMessage("The format should be a valid html color and start with #"); + }); } }