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)); }
private static void PopulateMetadataForUpload(ModelForm modelForm, FieldForm fieldForm) { if (fieldForm.Type == "Upload") { modelForm.ContainsFile = true; } }
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"); }
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()); } }
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); }