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

            base.Validate(errors);

            if (!string.IsNullOrWhiteSpace(NetFormatName) && IsSiteDotNet)
            {
                if (!Regex.IsMatch(NetFormatName, RegularExpressions.NetName))
                {
                    errors.ErrorFor(x => x.NetFormatName, TemplateStrings.NetNameInvalidFormat);
                }
                if (!PageTemplateRepository.ObjectFormatNetNameUnique(NetFormatName, ObjectId, Id))
                {
                    errors.ErrorFor(x => x.NetFormatName, TemplateStrings.NetNameNotUnique);
                }
                if (NetFormatName.Length > 255)
                {
                    errors.ErrorFor(x => x.NetFormatName, TemplateStrings.NetNameMaxLengthExceeded);
                }
            }

            if (NetLanguageId != null)
            {
                if (string.IsNullOrWhiteSpace(CodeBehind))
                {
                    errors.ErrorFor(n => n.CodeBehind, ObjectFormatStrings.CodeBehindRequired);
                }
            }

            if (!errors.IsEmpty)
            {
                throw errors;
            }
        }