Beispiel #1
0
        /// <summary>
        /// Generars the codigo domain.
        /// </summary>
        /// <returns></returns>
        public string GenerateCodeDomain()
        {
            TemplateFile template = TemplateFile.LoadTemplate(TemplateType.CS, Resources.class_Domain);

            TemplateSection sectionProperties = template.ExtractSection("PROPERTIES");
            TemplateSection sectionParameters = template.ExtractSection("PARAMETERS");

            TemplateSectionCollection propertiesSectionList = new TemplateSectionCollection();
            TemplateSectionCollection parametersSectionList = new TemplateSectionCollection();

            foreach (var entityField in Entity.Fields)
            {
                TemplateSection propertySection = sectionProperties.ExtractSection(entityField.SimpleTypeName);
                propertySection.ReplaceTag("PROPERTYNAME", entityField.ColumnName);
                propertiesSectionList.AddSection(propertySection);

                TemplateSection parameterSection = sectionParameters.ExtractSection(entityField.SimpleTypeName);
                parameterSection.ReplaceTag("PROPERTYNAME", entityField.ColumnName);
                parametersSectionList.AddSection(parameterSection);
            }

            template.ReplaceSection("PROPERTIES", propertiesSectionList);
            template.ReplaceSection("PARAMETERS", parametersSectionList);
            template.ReplaceTag("NAMESPACE_DOMAIN", Settings[CodeBaseConstants.NAMESPACE_DOMAIN].Value, false);
            template.ReplaceTag("CLASS_NAME_DOMAIN", DomainClassName, false);

            template.ReplaceTag("AUTHOR_NAME", Settings[CodeBaseConstants.AUTHOR_NAME].Value, false);
            template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false);

            return(template.Content);
        }
Beispiel #2
0
        public string GenerateScriptListAll()
        {
            TemplateFile template = TemplateFile.LoadTemplate(TemplateType.SQL, Resources.sp_ListAll);

            TemplateSection sectionSelectColumns = template.ExtractSection("SELECT_COLUMNS");

            TemplateSectionCollection selectColumnsSectionList = new TemplateSectionCollection();

            foreach (var entityField in Entity.Fields)
            {
                TemplateSection selectColumnsSection = sectionSelectColumns.ExtractSection("DEFAULT");
                selectColumnsSection.ReplaceTag("COLUMNNAME", entityField.ColumnName);
                selectColumnsSectionList.AddSection(selectColumnsSection);
            }

            template.ReplaceSection("SELECT_COLUMNS", selectColumnsSectionList, ",");

            template.ReplaceTag("LISTALL_STORED_PROCEDURE", ListAllStoredProcedureName, false);
            template.ReplaceTag("ENTITY_NAME", Entity.Name, false);

            template.ReplaceTag("AUTHOR_NAME", Settings[CodeBaseConstants.AUTHOR_NAME].Value, false);
            template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false);

            return(template.Content);
        }
Beispiel #3
0
        internal string GenerateViewIndex()
        {
            TemplateFile template = TemplateFile.LoadTemplate(TemplateType.HTML, Resources.view_Index);

            var instanceEntityName = StringHelper.ConverToInstanceName(CleanEntityName);

            var primaryEntityField = Entity.Fields.FirstOrDefault(f => f.IsPrimaryKey);

            if (primaryEntityField == null)
            {
                throw new DataException("Entity [" + Entity.Name + "] doesn't have primary key");
            }

            TemplateSection sectionHeader = template.ExtractSection("HEADER");
            TemplateSection sectionRow    = template.ExtractSection("ROW");

            TemplateSectionCollection propertiesHeaderList = new TemplateSectionCollection();
            TemplateSectionCollection propertiesRowList    = new TemplateSectionCollection();

            foreach (var entityField in Entity.Fields)
            {
                TemplateSection columnSection = sectionHeader.ExtractSection("COLUMN");
                columnSection.ReplaceTag("PROPERTYNAME", entityField.ColumnName);
                propertiesHeaderList.AddSection(columnSection);

                columnSection = sectionRow.ExtractSection("COLUMN");
                columnSection.ReplaceTag("PROPERTYNAME", entityField.ColumnName);
                propertiesRowList.AddSection(columnSection);
            }

            template.ReplaceSection("HEADER", propertiesHeaderList);
            template.ReplaceSection("ROW", propertiesRowList);

            template.ReplaceTag("PRIMARYKEY_PARAMETERNAME", primaryEntityField.ColumnName, false);
            template.ReplaceTag("NAMESPACE_MODELS", Settings[AspNetMvcCoreConstants.NAMESPACE_MODELS].Value, false);
            template.ReplaceTag("CLASS_NAME_MODEL", ModelClassName, false);

            template.ReplaceTag("INDEX_VIEWNAME", Settings[AspNetMvcCoreConstants.INDEX_VIEWNAME].Value, false);
            template.ReplaceTag("CREATE_VIEWNAME", Settings[AspNetMvcCoreConstants.CREATE_VIEWNAME].Value, false);
            template.ReplaceTag("EDIT_VIEWNAME", Settings[AspNetMvcCoreConstants.EDIT_VIEWNAME].Value, false);
            template.ReplaceTag("DETAILS_VIEWNAME", Settings[AspNetMvcCoreConstants.DETAILS_VIEWNAME].Value, false);
            template.ReplaceTag("DELETE_VIEWNAME", Settings[AspNetMvcCoreConstants.DELETE_VIEWNAME].Value, false);

            template.ReplaceTag("AUTHOR_NAME", Settings[AspNetMvcCoreConstants.AUTHOR_NAME].Value, false);
            template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false);

            return(template.Content);
        }
Beispiel #4
0
        internal string GenerateViewEdit()
        {
            TemplateFile template = TemplateFile.LoadTemplate(TemplateType.HTML, Resources.view_Edit);

            var instanceEntityName = StringHelper.ConverToInstanceName(CleanEntityName);

            var primaryEntityField = Entity.Fields.FirstOrDefault(f => f.IsPrimaryKey);

            if (primaryEntityField == null)
            {
                throw new DataException("Entity [" + Entity.Name + "] doesn't have primary key");
            }

            TemplateSection sectionForm = template.ExtractSection("FORM");

            TemplateSectionCollection propertiesFormList = new TemplateSectionCollection();

            foreach (var entityField in Entity.Fields.Where(f => !f.IsPrimaryKey))
            {
                TemplateSection fieldSection = sectionForm.ExtractSection("FIELD");
                fieldSection.ReplaceTag("PROPERTYNAME", entityField.ColumnName);
                propertiesFormList.AddSection(fieldSection);
            }

            template.ReplaceSection("FORM", propertiesFormList);

            template.ReplaceTag("PRIMARYKEY_PARAMETERNAME", primaryEntityField.ColumnName, false);
            template.ReplaceTag("NAMESPACE_MODELS", Settings[AspNetMvcCoreConstants.NAMESPACE_MODELS].Value, false);
            template.ReplaceTag("CLASS_NAME_MODEL", ModelClassName, false);

            template.ReplaceTag("EDIT_VIEWNAME", Settings[AspNetMvcCoreConstants.EDIT_VIEWNAME].Value, false);
            template.ReplaceTag("INDEX_VIEWNAME", Settings[AspNetMvcCoreConstants.INDEX_VIEWNAME].Value, false);

            template.ReplaceTag("AUTHOR_NAME", Settings[AspNetMvcCoreConstants.AUTHOR_NAME].Value, false);
            template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false);

            return(template.Content);
        }
Beispiel #5
0
        public string GenerateScriptDelete()
        {
            TemplateFile template = TemplateFile.LoadTemplate(TemplateType.SQL, Resources.sp_Delete);

            var primaryEntityField = Entity.Fields.FirstOrDefault(f => f.IsPrimaryKey);

            if (primaryEntityField == null)
            {
                throw new DataException("Entity [" + Entity.Name + "] doesn't have primary key");
            }

            template.ReplaceTag("PRIMARYKEY_DATATYPE", primaryEntityField.TypeName, false);
            template.ReplaceTag("PRIMARYKEY_PARAMETERNAME", primaryEntityField.ColumnName, false);
            template.ReplaceTag("PRIMARYKEY_PROPERTYNAME", primaryEntityField.ColumnName, false);

            template.ReplaceTag("DELETE_STORED_PROCEDURE", DeleteStoredProcedureName, false);
            template.ReplaceTag("ENTITY_NAME", Entity.Name, false);

            template.ReplaceTag("AUTHOR_NAME", Settings[CodeBaseConstants.AUTHOR_NAME].Value, false);
            template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false);

            return(template.Content);
        }
Beispiel #6
0
        public string GenerateScriptGetById()
        {
            TemplateFile template = TemplateFile.LoadTemplate(TemplateType.SQL, Resources.sp_GetByID);

            TemplateSection sectionSelectColumns = template.ExtractSection("SELECT_COLUMNS");

            TemplateSectionCollection selectColumnsSectionList = new TemplateSectionCollection();

            foreach (var entityField in Entity.Fields)
            {
                TemplateSection selectColumnsSection = sectionSelectColumns.ExtractSection("DEFAULT");
                selectColumnsSection.ReplaceTag("COLUMNNAME", entityField.ColumnName);
                selectColumnsSectionList.AddSection(selectColumnsSection);
            }

            template.ReplaceSection("SELECT_COLUMNS", selectColumnsSectionList, ",");

            var primaryEntityField = Entity.Fields.FirstOrDefault(f => f.IsPrimaryKey);

            if (primaryEntityField == null)
            {
                throw new DataException("Entity [" + Entity.Name + "] doesn't have primary key");
            }

            template.ReplaceTag("PRIMARYKEY_DATATYPE", primaryEntityField.TypeName, false);
            template.ReplaceTag("PRIMARYKEY_PARAMETERNAME", primaryEntityField.ColumnName, false);
            template.ReplaceTag("PRIMARYKEY_PROPERTYNAME", primaryEntityField.ColumnName, false);

            template.ReplaceTag("GETBYID_STORED_PROCEDURE", GetByIdStoredProcedureName, false);
            template.ReplaceTag("ENTITY_NAME", Entity.Name, false);

            template.ReplaceTag("AUTHOR_NAME", Settings[CodeBaseConstants.AUTHOR_NAME].Value, false);
            template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false);

            return(template.Content);
        }
Beispiel #7
0
        public string GenerateScriptSave()
        {
            TemplateFile template = TemplateFile.LoadTemplate(TemplateType.SQL, Resources.sp_Save);

            TemplateSection sectionParameters       = template.ExtractSection("PARAMETERS");
            TemplateSection sectionUpdateParameters = template.ExtractSection("UPDATE_PARAMETERS");
            TemplateSection sectionInsertColumns    = template.ExtractSection("INSERT_COLUMNS");
            TemplateSection sectionInsertParameters = template.ExtractSection("INSERT_PARAMETERS");

            TemplateSectionCollection parameterSectionList       = new TemplateSectionCollection();
            TemplateSectionCollection updateParameterSectionList = new TemplateSectionCollection();
            TemplateSectionCollection insertColumnsSectionList   = new TemplateSectionCollection();
            TemplateSectionCollection insertParameterSectionList = new TemplateSectionCollection();

            foreach (var entityField in Entity.Fields)
            {
                TemplateSection parameterSection = sectionParameters.ExtractSection("DEFAULT");
                parameterSection.ReplaceTag("PARAMETERNAME", entityField.ColumnName);
                parameterSection.ReplaceTag("DATATYPE", entityField.TypeName);
                parameterSectionList.AddSection(parameterSection);

                if (!entityField.IsPrimaryKey)
                {
                    TemplateSection updateParameterSection = sectionUpdateParameters.ExtractSection("DEFAULT");
                    updateParameterSection.ReplaceTag("PROPERTYNAME", entityField.ColumnName);
                    updateParameterSection.ReplaceTag("PARAMETERNAME", entityField.ColumnName);
                    updateParameterSectionList.AddSection(updateParameterSection);

                    TemplateSection insertColumnsSection = sectionInsertColumns.ExtractSection("DEFAULT");
                    insertColumnsSection.ReplaceTag("COLUMNNAME", entityField.ColumnName);
                    insertColumnsSectionList.AddSection(insertColumnsSection);

                    TemplateSection insertParameterSection = sectionInsertParameters.ExtractSection("DEFAULT");
                    insertParameterSection.ReplaceTag("PARAMETERNAME", entityField.ColumnName);
                    insertParameterSectionList.AddSection(insertParameterSection);
                }
            }

            template.ReplaceSection("PARAMETERS", parameterSectionList, ",");
            template.ReplaceSection("UPDATE_PARAMETERS", updateParameterSectionList, ",");
            template.ReplaceSection("INSERT_COLUMNS", insertColumnsSectionList, ",");
            template.ReplaceSection("INSERT_PARAMETERS", insertParameterSectionList, ",");

            var primaryEntityField = Entity.Fields.FirstOrDefault(f => f.IsPrimaryKey);

            if (primaryEntityField == null)
            {
                throw new DataException("Entity [" + Entity.Name + "] doesn't have primary key");
            }

            template.ReplaceTag("PRIMARYKEY_DATATYPE", primaryEntityField.TypeName, false);
            template.ReplaceTag("PRIMARYKEY_PARAMETERNAME", primaryEntityField.ColumnName, false);
            template.ReplaceTag("PRIMARYKEY_PROPERTYNAME", primaryEntityField.ColumnName, false);

            template.ReplaceTag("SAVE_STORED_PROCEDURE", SaveStoredProcedureName, false);
            template.ReplaceTag("ENTITY_NAME", Entity.Name, false);

            template.ReplaceTag("AUTHOR_NAME", Settings[CodeBaseConstants.AUTHOR_NAME].Value, false);
            template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false);

            return(template.Content);
        }
Beispiel #8
0
        internal string GenerateCodeController()
        {
            TemplateFile template = TemplateFile.LoadTemplate(TemplateType.CS, Resources.class_Controller);

            var instanceEntityName = StringHelper.ConverToInstanceName(CleanEntityName);

            var primaryEntityField = Entity.Fields.FirstOrDefault(f => f.IsPrimaryKey);

            if (primaryEntityField == null)
            {
                throw new DataException("Entity [" + Entity.Name + "] doesn't have primary key");
            }


            template.ReplaceTag("PRIMARYKEY_DATATYPE", DataTypeHelper.GetCSharpType(primaryEntityField.SimpleTypeName), false);
            template.ReplaceTag("PRIMARYKEY_PARAMETERNAME", primaryEntityField.ColumnName, false);
            template.ReplaceTag("PRIMARYKEY_LOCAL_VARIABLE", StringHelper.ConverToInstanceName(StringHelper.ConvertToSafeCodeName(primaryEntityField.ColumnName)), false);

            template.ReplaceTag("NAMESPACE_MODELS", Settings[AspNetMvcCoreConstants.NAMESPACE_MODELS].Value, false);
            template.ReplaceTag("NAMESPACE_CONTROLLER", Settings[AspNetMvcCoreConstants.NAMESPACE_CONTROLLER].Value, false);
            template.ReplaceTag("NAMESPACE_DBCONTEXT", Settings[AspNetMvcCoreConstants.NAMESPACE_DBCONTEXT].Value, false);

            template.ReplaceTag("INSTANCE_NAME_MODEL", instanceEntityName, false);
            template.ReplaceTag("CLASS_NAME_MODEL", ModelClassName, false);
            template.ReplaceTag("CLASS_NAME_CONTROLLER", ControllerClassName, false);
            template.ReplaceTag("VIEW_NAME", ViewBaseName, false);
            template.ReplaceTag("PROPERTIES_MODEL", string.Join(",", Entity.Fields.Select(t => t.ColumnName)), false);

            template.ReplaceTag("DETAILS_METHODNAME", Settings[AspNetMvcCoreConstants.DETAILS_METHODNAME].Value, false);
            template.ReplaceTag("CREATE_METHODNAME", Settings[AspNetMvcCoreConstants.CREATE_METHODNAME].Value, false);
            template.ReplaceTag("EDIT_METHODNAME", Settings[AspNetMvcCoreConstants.EDIT_METHODNAME].Value, false);
            template.ReplaceTag("DELETE_METHODNAME", Settings[AspNetMvcCoreConstants.DELETE_METHODNAME].Value, false);

            template.ReplaceTag("DBCONTEXT_NAME", Settings[AspNetMvcCoreConstants.DBCONTEXT_NAME].Value, false);

            template.ReplaceTag("AUTHOR_NAME", Settings[AspNetMvcCoreConstants.AUTHOR_NAME].Value, false);
            template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false);

            return(template.Content);
        }