public static async Task <String> Create(JsonSchema4 schema, Dictionary <String, JsonSchema4> others, String ns, bool generated)
        {
            bool hasBase = false;

            var baseWriter = new BaseModelWriter("", CreateAttributeBuilder());
            var baseClass  = ModelTypeGenerator.Create(schema, schema.GetPluralName(), baseWriter, ns, ns + ".ViewModels", allowPropertyCallback: p =>
            {
                if (p.CreateViewModel())
                {
                    hasBase = hasBase | p.IsAbstractOnViewModel();
                    return(p.IsAbstractOnViewModel());
                }
                return(false);
            });

            var mainWriter = new MainModelWriter(hasBase ? baseClass : null, "", CreateAttributeBuilder(), new NoAttributeBuilder(), schema.AllowCreated(), schema.AllowModified(),
                                                 a =>
            {
                var interfaces = new String[] { a.BaseClassName, }
                .Concat(a.Writer.GetAdditionalInterfaces());

                if (!generated)
                {
                    a.Builder.AppendLine(GetLinks(schema.GetPluralName()));
                }

                a.Builder.AppendLine(
                    $@"    public partial class {a.Name}{InterfaceListBuilder.Build(interfaces)}
    {{");

                a.Writer.CreateProperty(a.Builder, NameGenerator.CreatePascal(schema.GetKeyName()), new TypeWriterPropertyInfo(schema.GetKeyType()));
            }
                                                 )
            {
                AdditionalUsings =
                    $@"using {ns}.Controllers.Api;
using Threax.AspNetCore.Halcyon.Ext.ValueProviders;"
                    + schema.GetExtraNamespaces(StrConstants.FileNewline)
            };

            return(ModelTypeGenerator.Create(schema, schema.GetPluralName(), mainWriter, ns, ns + ".ViewModels",
                                             allowPropertyCallback: AllowProperty,
                                             additionalProperties: await AdditionalProperties(schema, others)));
        }
        public static String Create(JsonSchema4 schema, Dictionary <String, JsonSchema4> others, String ns)
        {
            bool hasBase = false;

            var baseWriter = new BaseModelWriter("Entity", CreateAttributeBuilder());
            var baseClass  = ModelTypeGenerator.Create(schema, schema.GetPluralName(), baseWriter, ns, ns + ".Database", allowPropertyCallback: p =>
            {
                if (p.CreateEntity())
                {
                    hasBase = hasBase | p.IsAbstractOnEntity();
                    return(p.IsAbstractOnEntity());
                }
                return(false);
            });

            var mainWriter = new MainModelWriter(hasBase ? baseClass : null, "Entity", CreateAttributeBuilder(), new NoAttributeBuilder(), schema.AllowCreated(), schema.AllowModified(),
                                                 a =>
            {
                var interfaces = new String[] { a.BaseClassName, }
                .Concat(a.Writer.GetAdditionalInterfaces());

                a.Builder.AppendLine(
                    $@"    public partial class {a.Name}Entity{InterfaceListBuilder.Build(interfaces)}
    {{
        [Key]"
                    );

                a.Writer.CreateProperty(a.Builder, NameGenerator.CreatePascal(schema.GetKeyName()), new TypeWriterPropertyInfo(schema.GetKeyType()));
            }
                                                 )
            {
                AdditionalUsings = schema.GetExtraNamespaces(StrConstants.FileNewline)
            };

            return(ModelTypeGenerator.Create(schema, schema.GetPluralName(), mainWriter, ns, ns + ".Database",
                                             allowPropertyCallback: AllowProperty,
                                             additionalProperties: AdditionalProperties(schema, others)));
        }
Esempio n. 3
0
        public static String Get(JsonSchema4 schema, String ns, bool generated)
        {
            String Model = NameGenerator.CreatePascal(schema.Title);

            return(Create(ns, Model, NameGenerator.CreatePascal(schema.GetKeyName()), schema.AllowCreated(), schema.AllowModified(), generated, schema.Properties.Values, schema.GetExtraNamespaces(StrConstants.FileNewline)));
        }