Skip to content

Preview image and fallback image url should be different #161

@linkdotnet

Description

@linkdotnet

It can happen, thanks to copy&paste, that the preview image URL and the fallback image URL are literally the same.
That doesn't make much sense and should either pop up a warning message or even a validation error.

## Possible Solution
We can create our own attribute to do that:

[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public sealed class FallbackUrlValidation : ValidationAttribute
{
    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    {
        var model = validationContext.ObjectInstance as CreateNewModel;

        if (model.PreviewImageUrl == model.PreviewImageUrlFallback)
        {
            return new ValidationResult("PreviewImageUrl and PreviewImageUrlFallback should not be the same");
        }

        return ValidationResult.Success;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions