public static RequestModelExtensionsClassDefinition GetRequestExtensionsClassDefinition(this AspNetCoreProject project, ITable table)
        {
            var definition = new RequestModelExtensionsClassDefinition
            {
                Namespaces =
                {
                    "System",
                    project.GetEntityLayerNamespace()
                },
                Namespace      = project.GetRequestsNamespace(),
                AccessModifier = AccessModifier.Public,
                IsStatic       = true,
                Name           = string.Format("{0}RequestExtensions", project.EntityFrameworkCoreProject.GetEntityName(table))
            };

            if (!project.Database.HasDefaultSchema(table))
            {
                definition.Namespaces.AddUnique(project.GetEntityLayerNamespace(table.Schema));
            }

            definition.Methods.Add(GetToEntityMethod(project, table));
            definition.Methods.Add(GetToRequestModelMethod(project, table));

            return(definition);
        }
        public static CSharpClassDefinition GetRequestModelExtensionsClassDefinition(this AspNetCoreProject project)
        {
            var classDefinition = new CSharpClassDefinition
            {
                Namespaces = new List <string>
                {
                    "System",
                    project.GetEntityLayerNamespace()
                },
                Namespace = project.GetRequestModelsNamespace(),
                Name      = "Extensions",
                IsStatic  = true
            };

            foreach (var table in project.Database.Tables)
            {
                if (!table.HasDefaultSchema())
                {
                    classDefinition.Namespaces.AddUnique(project.GetEntityLayerNamespace(table.Schema));
                }

                classDefinition.Methods.Add(GetToEntityMethod(project, table));
                classDefinition.Methods.Add(GetToRequestModelMethod(project, table));
            }

            return(classDefinition);
        }
Ejemplo n.º 3
0
        public static CSharpClassDefinition GetResponsesExtensionsClassDefinition(this AspNetCoreProject project, ITable table)
        {
            var classDefinition = new CSharpClassDefinition
            {
                Namespaces = new List <string>
                {
                    "System",
                    "System.ComponentModel.DataAnnotations",
                    table.HasDefaultSchema() ? project.GetEntityLayerNamespace() : project.GetEntityLayerNamespace(table.Schema),
                    table.HasDefaultSchema() ? project.GetEntityLayerNamespace() : project.GetEntityLayerNamespace(table.Schema)
                },
                Namespace = project.GetRequestModelsNamespace(),
                Name      = table.GetRequestModelName()
            };

            var selection = project.GetSelection(table);

            foreach (var column in table.Columns.Where(item => selection.Settings.ConcurrencyToken != item.Name).ToList())
            {
                var property = new PropertyDefinition(EfCore.DatabaseExtensions.ResolveType(project.Database, column), column.GetPropertyName());

                if (table.PrimaryKey?.Key.Count > 0 && table.PrimaryKey?.Key.First() == column.Name)
                {
                    property.Attributes.Add(new MetadataAttribute("Key"));
                }

                if (!column.Nullable && table.PrimaryKey?.Key.Count > 0 && table.PrimaryKey?.Key.First() != column.Name)
                {
                    property.Attributes.Add(new MetadataAttribute("Required"));
                }

                if (project.Database.ColumnIsString(column) && column.Length > 0)
                {
                    property.Attributes.Add(new MetadataAttribute("StringLength", column.Length.ToString()));
                }

                classDefinition.Properties.Add(property);
            }

            return(classDefinition);
        }
        public static RequestClassDefinition GetRequestClassDefinition(this AspNetCoreProject project, ITable table)
        {
            var definition = new RequestClassDefinition
            {
                Namespaces =
                {
                    "System",
                    "System.ComponentModel.DataAnnotations",
                    project.Database.HasDefaultSchema(table) ? project.GetEntityLayerNamespace() : project.GetEntityLayerNamespace(table.Schema)
                },
                Namespace      = project.GetRequestsNamespace(),
                AccessModifier = AccessModifier.Public,
                Name           = project.GetRequestName(table)
            };

            var selection = project.EntityFrameworkCoreProject.GetSelection(table);

            foreach (var column in table.Columns.Where(item => selection.Settings.ConcurrencyToken != item.Name).ToList())
            {
                var property = new PropertyDefinition(AccessModifier.Public, project.Database.ResolveDatabaseType(column), project.GetPropertyName(table, column))
                {
                    IsAutomatic = true
                };

                if (table.PrimaryKey?.Key.Count > 0 && table.PrimaryKey?.Key.First() == column.Name)
                {
                    property.Attributes.Add(new MetadataAttribute("Key"));
                }

                if (!column.Nullable && table.PrimaryKey?.Key.Count > 0 && table.PrimaryKey?.Key.First() != column.Name)
                {
                    property.Attributes.Add(new MetadataAttribute("Required"));
                }

                if (project.Database.ColumnIsString(column) && column.Length > 0)
                {
                    property.Attributes.Add(new MetadataAttribute("StringLength", column.Length.ToString()));
                }

                definition.Properties.Add(property);
            }

            definition.SimplifyDataTypes();

            return(definition);
        }