示例#1
0
        public void RenderPropertyWithEntLibValidationAttributes()
        {
            IColumn column = m_IColumn;

            if (column.Name.ToLower() != script.Settings.DataOptions.VersionColumnName.ToLower())
            {
                if (column.LanguageType.ToString().ToLower() == "string")
                {
                    if (!column.IsNullable)
                    {
                        output.autoTabLn("[NotNullValidator(MessageTemplate = \"" + StringFormatter.NormalizePropertyName(column.Name) + " is required.\")]");
                        if (column.Name.ToLower().Contains("phone"))
                        {
                            output.autoTabLn("[StringLengthValidator(14, " + column.CharacterMaxLength + ", MessageTemplate=\"" + column.Name + " is invalid. Format: (###) ###-####.\")]");
                        }
                        else
                        {
                            if (!column.DataTypeName.Contains("text") && !column.DataTypeNameComplete.ToLower().Contains("nvarchar(max)"))
                            {
                                output.autoTabLn("[StringLengthValidator(1, " + column.CharacterMaxLength + ", MessageTemplate=\"" + StringFormatter.NormalizePropertyName(column.Name) + " must be between 1 and " + column.CharacterMaxLength + " characters.\")]");
                            }
                            if (column.DataTypeName.Contains("text") || column.DataTypeNameComplete.ToLower().Contains("varchar(max)"))
                            {
                                //output.autoTabLn("[DataType(DataType.MultilineText)]");
                            }
                        }
                    }
                    else
                    {
                        if (column.DataTypeName.Contains("text") || column.DataTypeNameComplete.ToLower().Contains("varchar(max)"))
                        {
                            //output.autoTabLn("[DataType(DataType.MultilineText)]");
                        }
                    }
                    output.autoTabLn(StringFormatter.CreateDisplayName(column.Name));
                    output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                    output.autoTabLn("");
                }
                else if (column.IsInPrimaryKey)
                {
                    //output.autoTabLn("[ScaffoldColumn(false)]");
                    output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                    output.autoTabLn("");
                }
                else
                {
                    //output.autoTabLn(StringFormatter.CreateDisplayName(column.Name));
                    if (!column.IsNullable)
                    {
                        output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                        output.autoTabLn("");
                    }
                    else
                    {
                        if (column.DataTypeName == "bit")
                        {
                            output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                            output.autoTabLn("");
                        }
                        else
                        {
                            output.autoTabLn("public " + column.LanguageType + "? " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                            output.autoTabLn("");
                        }
                    }
                }
            }
            else
            {
                if (!column.IsNullable)
                {
                    if (column.LanguageType == "byte[]")
                    {
                        if (column.Name.ToLower() == script.Settings.DataOptions.VersionColumnName.ToLower())
                        {
                            //output.autoTabLn("[HiddenInput(DisplayValue=false)]");
                            output.autoTabLn("public string " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                            output.autoTabLn("");
                        }
                        else
                        {
                            output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                            output.autoTabLn("");
                        }
                    }
                    else
                    {
                        output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                        output.autoTabLn("");
                    }
                }
                else
                {
                    if (column.LanguageType == "byte[]")
                    {
                        if (column.Name.ToLower() == script.Settings.DataOptions.VersionColumnName.ToLower())
                        {
                            //output.autoTabLn("[HiddenInput(DisplayValue=false)]");
                            output.autoTabLn("public string " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                            output.autoTabLn("");
                        }
                        else
                        {
                            output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                            output.autoTabLn("");
                        }
                    }
                    else
                    {
                        output.autoTabLn("public " + column.LanguageType + "? " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                        output.autoTabLn("");
                    }
                }
            }
        }
        public override void Render()
        {
            if (!_omitList.Where(o => o == this.Alias.ToLower()).Any())
            {
                IColumn column = Column;
                if (column.Name.ToLower() != _script.Settings.DataOptions.VersionColumnName.ToLower())
                {
                    if (column.LanguageType.ToString().ToLower() == "string")
                    {
                        if (!column.IsNullable)
                        {
                            _output.autoTabLn("[Required(ErrorMessage = \"" + StringFormatter.NormalizePropertyName(column.Name) + " is required.\")]");
                            if (column.Name.ToLower().Contains("phone"))
                            {
                                _output.autoTabLn("[StringLength(14, ErrorMessage=\"" + column.Name + " is invalid. Format: (###) ###-####.\")]");
                            }
                            else
                            {
                                if (!column.DataTypeName.Contains("text") && !column.DataTypeNameComplete.ToLower().Contains("nvarchar(max)"))
                                {
                                    _output.autoTabLn("[StringLength(" + column.CharacterMaxLength + ", ErrorMessage=\"" + StringFormatter.NormalizePropertyName(column.Name) + " must be between 1 and " + column.CharacterMaxLength + " characters.\")]");
                                }
                                if (column.DataTypeName.Contains("text") || column.DataTypeNameComplete.ToLower().Contains("varchar(max)"))
                                {
                                    _output.autoTabLn("[DataType(DataType.MultilineText)]");
                                    _output.autoTabLn("[UIHint(\"Editor\")]");
                                }
                            }
                        }
                        else
                        {
                            if (column.DataTypeName.Contains("text") || column.DataTypeNameComplete.ToLower().Contains("varchar(max)"))
                            {
                                _output.autoTabLn("[DataType(DataType.MultilineText)]");
                            }
                        }
                        _output.autoTabLn(StringFormatter.CreateDisplayName(column.Name));
                        _output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                        _output.autoTabLn("");
                    }
                    else if (column.IsInPrimaryKey)
                    {
                        _output.autoTabLn("[Key]");
                        _output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                        _output.autoTabLn("");
                    }
                    else
                    {
                        _output.autoTabLn(StringFormatter.CreateDisplayName(column.Name));
                        if (!column.IsNullable)
                        {
                            _output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                            _output.autoTabLn("");
                        }
                        else
                        {
                            if (column.DataTypeName == "bit")
                            {
                                _output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                                _output.autoTabLn("");
                            }
                            else
                            {
                                _output.autoTabLn("public " + column.LanguageType + "? " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                                _output.autoTabLn("");
                            }
                        }
                    }
                }
                else
                {
                    if (!column.IsNullable)
                    {
                        if (column.DataTypeName == "timestamp")
                        {
                        }


                        if (column.LanguageType == "byte[]")
                        {
                            if (column.Name.ToLower() == _script.Settings.DataOptions.VersionColumnName.ToLower())
                            {
                                _output.autoTabLn("[HiddenInput(DisplayValue=false)]");
                                _output.autoTabLn("[Timestamp]");
                                _output.autoTabLn("public byte[] " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                                _output.autoTabLn("");
                            }
                            else
                            {
                                _output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                                _output.autoTabLn("");
                            }
                        }
                        else
                        {
                            _output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                            _output.autoTabLn("");
                        }
                    }
                    else
                    {
                        if (column.LanguageType == "byte[]")
                        {
                            if (column.Name.ToLower() == _script.Settings.DataOptions.VersionColumnName.ToLower())
                            {
                                _output.autoTabLn("[HiddenInput(DisplayValue=false)]");
                                _output.autoTabLn("[Timestamp]");
                                _output.autoTabLn("public byte[] " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                                _output.autoTabLn("");
                            }
                            else
                            {
                                _output.autoTabLn("public " + column.LanguageType + " " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                                _output.autoTabLn("");
                            }
                        }
                        else
                        {
                            _output.autoTabLn("public " + column.LanguageType + "? " + _util.CleanUpProperty(column.Name) + " { get; set; }");
                            _output.autoTabLn("");
                        }
                    }
                }
            }
        }