示例#1
0
        public static void example_log_modelFactory <T>()
        {
            POSContext context = new POSContextFactory().CreateDbContext(new string[] { });
            ModelForm  model   = ModelFormFactory.BuildModelForm(context, typeof(T));

            Log(JsonConvert.SerializeObject(model, Formatting.Indented));
        }
示例#2
0
 private static void PopulateMetadataForUpload(ModelForm modelForm, FieldForm fieldForm)
 {
     if (fieldForm.Type == "Upload")
     {
         modelForm.ContainsFile = true;
     }
 }
示例#3
0
        public static void example_render_model()
        {
            POSContext            context   = new POSContextFactory().CreateDbContext(new string[] { });
            ModelForm             model     = ModelFormFactory.BuildModelForm(context, typeof(Order));
            AbstractBaseGenerator generator = new ScribanGeneratorConcrete();

            generator.Build("form-entity.scriban", "form-order.vue", model).Wait();
            Log("complete");
        }
示例#4
0
        private static void PopulateMetadataForFieldSelect(ModelForm modelForm, FieldForm fieldForm, IProperty item)
        {
            if (fieldForm.Type == "select" && item.IsForeignKey())
            {
                IForeignKey foreignKey    = item.GetContainingForeignKeys().First();
                var         declaringType = foreignKey.PrincipalKey.DeclaringEntityType;

                fieldForm.ForeignEntityName = declaringType.ClrType.Name;
                fieldForm.IsForeingKey      = true;
                fieldForm.IsCollection      = foreignKey.DependentToPrincipal.IsCollection();
                modelForm.DependentToPrincipalFields.Add(fieldForm);
            }
            else if (fieldForm.Type == "select" && item.ClrType.IsEnum == true)
            {
                Enum.GetNames(item.GetType());
            }
        }
示例#5
0
        public static ModelForm BuildModelForm(DbContext context, Type type)
        {
            var modelForm = new ModelForm();

            modelForm.ModelName = type.Name;
            var assembly = type.Assembly;
            var metadata = context.Entry(assembly.CreateInstance(type.FullName)).Metadata;
            //var foreignKeys = metadata.GetReferencingForeignKeys(); to get the collections for the entities where product is principal
            var properties = metadata.GetProperties().Where(_ => !_.IsShadowProperty);
            var formLayout = type.GetCustomAttribute <FormLayoutAttribute>();

            foreach (var item in  properties)
            {
                var fieldForm = CreateFieldForm(item);

                modelForm.FieldForms.Add(fieldForm);

                fieldForm.Type = GetTypeInput(item);

                PopulateMetadataForFieldSelect(modelForm, fieldForm, item);
                PopulateMetadataForUpload(modelForm, fieldForm);
            }
            return(modelForm);
        }