public override ValidationState Validate(ContactInput input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            ValidationState validationState = new ValidationState();

            if (string.IsNullOrEmpty(input.Message))
            {
                validationState.Errors.Add(CreateValidationError(input.Message, "Message", "Message.RequiredError", "Message is not set."));
            }

            if (input.Email != null)
            {
                if (string.IsNullOrEmpty(input.Email))
                {
                    validationState.Errors.Add(CreateValidationError(input.Email, "Email", "ContactForm.Email", "Email must be set to submit feedback"));
                }

                if (!string.IsNullOrEmpty(input.Email) && !Expressions.IsMatch("IsEmail", input.Email))
                {
                    validationState.Errors.Add(CreateValidationError(input.Email, "Email", "UserBase.Email", "Email is not valid."));
                }
            }

            return(validationState);
        }
Пример #2
0
        public override ValidationState Validate(Post post)
        {
            if (post == null)
            {
                throw new ArgumentNullException("post");
            }

            ValidationState validationState = new ValidationState();

            if (post.Creator == null)
            {
                validationState.Errors.Add(CreateValidationError(post.Creator, "Creator.RequiredError", "Creator is not set."));
            }

            if (post.Area == null)
            {
                validationState.Errors.Add(CreateValidationError(post.Area, "Area.RequiredError", "Area is not set."));
            }

            post.Title = post.Title.Trim();
            if (string.IsNullOrEmpty(post.Title))
            {
                validationState.Errors.Add(CreateValidationError(post.Title, "Title.RequiredError", "Title is not set."));
            }
            else
            {
                if (post.Title.Length > 250)
                {
                    validationState.Errors.Add(CreateValidationError(post.Title, "Title.MaxLengthExceededError", "Title must be {0} characters or less.", 250));
                }
            }

            post.Body = post.Body.Trim();
            if (string.IsNullOrEmpty(post.Body))
            {
                validationState.Errors.Add(CreateValidationError(post.Body, "Body.RequiredError", "Body is not set."));
            }

            post.Slug = post.Slug.Trim();
            if (string.IsNullOrEmpty(post.Slug))
            {
                validationState.Errors.Add(CreateValidationError(post.Slug, "Slug.RequiredError", "Slug is not set."));
            }
            else
            {
                if (!Expressions.IsMatch("IsSlug", post.Slug))
                {
                    validationState.Errors.Add(CreateValidationError(post.Slug, "Slug.NotValidError", "Slug is not valid."));
                }
            }

            return(validationState);
        }
Пример #3
0
        public override ValidationState Validate(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            ValidationState validationState = new ValidationState();

            if (string.IsNullOrEmpty(user.Name))
            {
                validationState.Errors.Add(CreateValidationError(user.Name, "Name.RequiredError", "Name is not set"));
            }
            else
            {
                if (user.Name.Length > 256)
                {
                    validationState.Errors.Add(CreateValidationError(user.Name, "Name.MaxLengthExceededError", "Username must be less than or equal to {0} characters long.", 256));
                }
            }

            if (string.IsNullOrEmpty(user.DisplayName))
            {
                validationState.Errors.Add(CreateValidationError(user.DisplayName, "DisplayName.RequiredError", "DisplayName is not set"));
            }
            else
            {
                if (user.DisplayName.Length > 256)
                {
                    validationState.Errors.Add(CreateValidationError(user.DisplayName, "DisplayName.MaxLengthExceededError", "DisplayName must be less than or equal to {0} characters long.", 256));
                }
            }

            if (!string.IsNullOrEmpty(user.Email))
            {
                if (user.Email.Length > 256)
                {
                    validationState.Errors.Add(CreateValidationError(user.Email, "Email.MaxLengthExceededError", "Email must be less than or equal to {0} characters long.", 256));
                }
                else if (!Expressions.IsMatch("IsEmail", user.Email))
                {
                    validationState.Errors.Add(CreateValidationError(user.Email, "Email.InvalidError", "Email is invalid."));
                }
            }

            return(validationState);
        }
Пример #4
0
        public override ValidationState Validate(Area area)
        {
            if (area == null)
            {
                throw new ArgumentNullException("area");
            }

            ValidationState validationState = new ValidationState();

            if (string.IsNullOrEmpty(area.Name))
            {
                validationState.Errors.Add(CreateValidationError(area.Name, "Name.RequiredError", "Name is not set."));
            }
            else
            {
                if (!Expressions.IsMatch("AreaName", area.Name))
                {
                    validationState.Errors.Add(CreateValidationError(area.Name, "Name.InvalidError", "Name is invalid and must be alphanumeric."));
                }
                else if (area.Name.Length > 256)
                {
                    validationState.Errors.Add(CreateValidationError(area.Name, "Name.MaxLengthExceededError", "Name must be less than or equal to {0} characters", 256));
                }
            }

            if (string.IsNullOrEmpty(area.DisplayName))
            {
                validationState.Errors.Add(CreateValidationError(area.DisplayName, "DisplayName.RequiredError", "DisplayName is not set."));
            }
            else
            {
                if (area.DisplayName.Length > 256)
                {
                    validationState.Errors.Add(CreateValidationError(area.DisplayName, "DisplayName.MaxLengthExceededError", "DisplayName must be less than or equal to {0} characters", 256));
                }
            }

            if (!string.IsNullOrEmpty(area.Description) && area.Description.Length > 256)
            {
                validationState.Errors.Add(CreateValidationError(area.Description, "Description.MaxLengthExceededError", "Description must be less than or equal to {0} characters", 256));
            }

            return(validationState);
        }
Пример #5
0
        public override ValidationState Validate(PostSubscription postSubscription)
        {
            if (postSubscription == null)
            {
                throw new ArgumentNullException("postSubscription");
            }

            ValidationState validationState = new ValidationState();

            if (string.IsNullOrEmpty(postSubscription.User.Email))
            {
                validationState.Errors.Add(CreateValidationError(postSubscription.User.Email, "Email.RequiredError", "Email is required."));
            }
            else if (!Expressions.IsMatch("IsEmail", postSubscription.User.Email))
            {
                validationState.Errors.Add(CreateValidationError(postSubscription.User.Email, "Email.InvalidError", "Email is invalid."));
            }

            return(validationState);
        }
Пример #6
0
        public override ValidationState Validate(Comment comment)
        {
            if (comment == null)
            {
                throw new ArgumentNullException("comment");
            }

            ValidationState validationState = new ValidationState();

            if (string.IsNullOrEmpty(comment.Body))
            {
                validationState.Errors.Add(CreateValidationError(comment.Body, "Body.RequiredError", "Comment (body) is not set."));
            }

            if (comment.Creator == null)
            {
                validationState.Errors.Add(CreateValidationError(comment.Creator, "Creator.RequiredError", "Comment creator is not set."));
            }

            if (comment.CreatorIP < 0)
            {
                validationState.Errors.Add(CreateValidationError(comment.CreatorIP, "CreatorIP.InvalidError", "CreatorIP value is invalid."));
            }

            if (comment.CreatorUserAgent == null)
            {
                validationState.Errors.Add(CreateValidationError(comment.CreatorUserAgent, "CreatorUserAgent.RequiredError", "CreatorUserAgent string is not set."));
            }

            if (comment.Language == null)
            {
                validationState.Errors.Add(CreateValidationError(comment.Language, "Language.RequiredError", "Comment language is not set"));
            }

            if (comment.State == EntityState.NotSet)
            {
                validationState.Errors.Add(CreateValidationError(comment.State, "State.RequiredError", "Comment state is not set."));
            }

            return(validationState);
        }
Пример #7
0
        public override ValidationState Validate(Site input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            ValidationState validationState = new ValidationState();

            if (string.IsNullOrEmpty(input.CommentStateDefault))
            {
                validationState.Errors.Add(CreateValidationError(input.CommentStateDefault, "CommentStateDefault", "CommentStateDefault.RequiredError", "CommentStateDefault is not set."));
            }
            else
            {
                if (!(input.CommentStateDefault == EntityState.Normal.ToString() || input.CommentStateDefault == EntityState.PendingApproval.ToString()))
                {
                    validationState.Errors.Add(CreateValidationError(input.CommentStateDefault, "CommentStateDefault", "CommentStateDefault.InvalidError", "Invalid value specified for CommentStateDefault."));
                }
            }

            if (string.IsNullOrEmpty(input.SkinsStylesPath))
            {
                validationState.Errors.Add(CreateValidationError(input.SkinsStylesPath, "SkinsStylesPath", "CssPath.RequiredError", "CssPath is not set."));
            }

            if (string.IsNullOrEmpty(input.DisplayName))
            {
                validationState.Errors.Add(CreateValidationError(input.DisplayName, "DisplayName", "DisplayName.RequiredError", "DisplayName is not set."));
            }

            if (input.Host == null)
            {
                validationState.Errors.Add(CreateValidationError(input.Host, "Host", "Host.RequiredError", "Host is not set."));
            }

            if (string.IsNullOrEmpty(input.LanguageDefault))
            {
                validationState.Errors.Add(CreateValidationError(input.LanguageDefault, "LanguageDefault", "LanguageDefault.RequiredError", "LanguageDefault is not set."));
            }

            if (string.IsNullOrEmpty(input.Name))
            {
                validationState.Errors.Add(CreateValidationError(input.Name, "Name", "Name.RequiredError", "Name is not set."));
            }

            if (string.IsNullOrEmpty(input.PageTitleSeparator))
            {
                validationState.Errors.Add(CreateValidationError(input.PageTitleSeparator, "PageTitleSeparator", "PageTitleSeparator.RequiredError", "PageTitleSeparator is not set."));
            }

            if (string.IsNullOrEmpty(input.SkinsScriptsPath))
            {
                validationState.Errors.Add(CreateValidationError(input.SkinsScriptsPath, "SkinsScriptsPath", "ScriptsPath.RequiredError", "ScriptsPath is not set."));
            }

            if (string.IsNullOrEmpty(input.AdminSkin))
            {
                validationState.Errors.Add(CreateValidationError(input.AdminSkin, "AdminSkin", "AdminSkin.RequiredError", "AdminSkin is not set."));
            }

            return(validationState);
        }
Пример #8
0
        public override ValidationState Validate(Site site)
        {
            if (site == null)
            {
                throw new ArgumentNullException("site");
            }

            ValidationState validationState = new ValidationState();

            if (string.IsNullOrEmpty(site.CommentStateDefault))
            {
                validationState.Errors.Add(CreateValidationError(site.CommentStateDefault, "CommentStateDefault.RequiredError", "CommentStateDefault is not set."));
            }
            else
            {
                if (!(site.CommentStateDefault == EntityState.Normal.ToString() || site.CommentStateDefault == EntityState.PendingApproval.ToString()))
                {
                    validationState.Errors.Add(CreateValidationError(site.CommentStateDefault, "CommentStateDefault.InvalidError", "Invalid value specified for CommentStateDefault."));
                }
            }

            if (string.IsNullOrEmpty(site.CssPath))
            {
                validationState.Errors.Add(CreateValidationError(site.CssPath, "CssPath.RequiredError", "CssPath is not set."));
            }
            else
            {
                if (!site.CssPath.Contains("{0}"))
                {
                    validationState.Errors.Add(CreateValidationError(site.CssPath, "CssPath.FormatError", "CssPath must contain '{0}'."));
                }
            }

            if (string.IsNullOrEmpty(site.DisplayName))
            {
                validationState.Errors.Add(CreateValidationError(site.DisplayName, "DisplayName.RequiredError", "DisplayName is not set."));
            }

            if (site.Host == null)
            {
                validationState.Errors.Add(CreateValidationError(site.Host, "Host.RequiredError", "Host is not set."));
            }

            if (string.IsNullOrEmpty(site.LanguageDefault))
            {
                validationState.Errors.Add(CreateValidationError(site.LanguageDefault, "LanguageDefault.RequiredError", "LanguageDefault is not set."));
            }

            if (string.IsNullOrEmpty(site.Name))
            {
                validationState.Errors.Add(CreateValidationError(site.Name, "Name.RequiredError", "Name is not set."));
            }

            if (string.IsNullOrEmpty(site.PageTitleSeparator))
            {
                validationState.Errors.Add(CreateValidationError(site.PageTitleSeparator, "PageTitleSeparator.RequiredError", "PageTitleSeparator is not set."));
            }

            if (string.IsNullOrEmpty(site.ScriptsPath))
            {
                validationState.Errors.Add(CreateValidationError(site.ScriptsPath, "ScriptsPath.RequiredError", "ScriptsPath is not set."));
            }
            else
            {
                if (!site.ScriptsPath.Contains("{0}"))
                {
                    validationState.Errors.Add(CreateValidationError(site.ScriptsPath, "ScriptsPath.FormatError", "ScriptsPath must contain '{0}'."));
                }
            }

            if (string.IsNullOrEmpty(site.SkinDefault))
            {
                validationState.Errors.Add(CreateValidationError(site.SkinDefault, "SkinDefault.RequiredError", "SkinDefault is not set."));
            }

            return(validationState);
        }