Example #1
0
        protected override bool IsValid(PropertyValidatorContext context)
        {
            var fileToValidate = context.PropertyValue as IFormFile;

            //if the user did not upload an image, return true as we don't need to validate anything
            if (_isImage && fileToValidate == null)
            {
                return(true);
            }
            //if the user did not upload a file for board email, return true as we don't need to validate anything
            else if (_isBoardEmail && fileToValidate == null)
            {
                return(true);
            }
            //otherwise if the file is null (in case of meetingminutes) - user must upload a file so return false
            else if (fileToValidate == null)
            {
                return(false);
            }

            var(Valid, ErrorMessage) = _fileValidate.ValidateFile(fileToValidate, _isImage);

            if (!Valid)
            {
                context.MessageFormatter.AppendArgument("ErrorMessage", ErrorMessage);
                return(false);
            }

            return(true);
        }
        protected override async Task <bool> IsValidAsync(PropertyValidatorContext context, CancellationToken cancellation)
        {
            var fileToValidate = context.PropertyValue as IFormFile;

            var(Valid, ErrorMessage) = _fileValidate.ValidateFile(fileToValidate);

            if (!Valid)
            {
                context.MessageFormatter.AppendArgument("ErrorMessage", ErrorMessage);
                return(false);
            }

            return(true);
        }