Exemplo n.º 1
0
        public override void Validate()
        {
            var errors = new RulesException <Page>();

            base.Validate(errors);

            if (!PageTemplateRepository.PageFileNameUnique(FileName, PageTemplate.Id, Id))
            {
                errors.ErrorFor(x => x.FileName, TemplateStrings.NetNameNotUnique);
            }

            if (!string.IsNullOrWhiteSpace(CustomClass))
            {
                if (!Regex.IsMatch(CustomClass, RegularExpressions.NetName))
                {
                    errors.ErrorFor(x => x.CustomClass, TemplateStrings.CustomClassInvalidFormat);
                }
            }

            if (!string.IsNullOrWhiteSpace(Folder))
            {
                if (!Regex.IsMatch(Folder, RegularExpressions.RelativeWindowsFolderPath))
                {
                    errors.ErrorFor(x => x.Folder, TemplateStrings.FolderNameInvalidFormat);
                }
            }

            if (PageTemplate.SiteIsDotNet)
            {
                if (!string.IsNullOrWhiteSpace(CustomClass))
                {
                    if (!Regex.IsMatch(CustomClass, RegularExpressions.NetName))
                    {
                        errors.ErrorFor(x => x.CustomClass, TemplateStrings.CustomClassInvalidFormat);
                    }
                    if (CustomClass.Length > 255)
                    {
                        errors.ErrorFor(x => x.CustomClass, TemplateStrings.CustomClassMaxLengthExceeded);
                    }
                }

                if (!string.IsNullOrWhiteSpace(Folder))
                {
                    if (!Regex.IsMatch(Folder, RegularExpressions.RelativeWindowsFolderPath))
                    {
                        errors.ErrorFor(x => x.Folder, TemplateStrings.FolderNameInvalidFormat);
                    }
                    if (Folder.Length > 255)
                    {
                        errors.ErrorFor(x => x.Folder, TemplateStrings.FolderNameMaxLengthExceeded);
                    }
                }
            }
            if (!errors.IsEmpty)
            {
                throw errors;
            }
        }