public DynamicPropertyIndexViewModel BuildDynamicPropertyIndexViewModel(DynamicPropertyMetadata dynamicPropertyMetadata) { var dynamicPropertyIndexViewModel = new DynamicPropertyIndexViewModel(dynamicPropertyMetadata); if (dynamicPropertyMetadata.DataType() == DataType.Password) { return(null); } dynamicPropertyIndexViewModel.AllowSort = dynamicPropertyMetadata.AllowSort(); if (dynamicPropertyMetadata is DynamicForiegnKeyPropertyMetadata) { dynamicPropertyIndexViewModel.ViewModelPropertyName = "Item." + dynamicPropertyMetadata.PropertyName(); //ToDo: This logic could probably be pushed back to a lower level if (dynamicPropertyMetadata.DisplayName() == dynamicPropertyMetadata.PropertyName()) { dynamicPropertyIndexViewModel.DisplayName = ((DynamicForiegnKeyPropertyMetadata)dynamicPropertyMetadata).ComplexEntityPropertyMetadata.PropertyName(); } dynamicPropertyIndexViewModel.SortExpression = ((DynamicForiegnKeyPropertyMetadata)dynamicPropertyMetadata).ComplexEntityPropertyMetadata.PropertyName() + "." + ((DynamicForiegnKeyPropertyMetadata)dynamicPropertyMetadata).ComplexDynamicEntityMetadata.DefaultProperty().PropertyName(); dynamicPropertyIndexViewModel.PartialViewName = "_DynamicDisplayHyperlink"; } else if (dynamicPropertyMetadata.IsSimple()) { dynamicPropertyIndexViewModel.ViewModelPropertyName = "Item." + dynamicPropertyMetadata.PropertyName(); dynamicPropertyIndexViewModel.PartialViewName = "_DynamicDisplay"; } else if (dynamicPropertyMetadata.IsDynamicCollection()) { dynamicPropertyIndexViewModel.ViewModelPropertyName = "Item." + dynamicPropertyMetadata.PropertyName(); dynamicPropertyIndexViewModel.PartialViewName = "_DynamicDisplayHyperlink"; } return(dynamicPropertyIndexViewModel); }
public DynamicTableHeaderViewModel(DynamicPropertyIndexViewModel dynamicPropertyIndexViewModel, RouteValueDictionaryWrapper routeValueDictionaryWrapper, string typeName) { DisplayName = dynamicPropertyIndexViewModel.DisplayName; SortExpression = dynamicPropertyIndexViewModel.SortExpression; AllowSort = dynamicPropertyIndexViewModel.AllowSort; TypeName = typeName; RouteValueDictionaryWrapper = routeValueDictionaryWrapper; ViewModelPropertyName = dynamicPropertyIndexViewModel.ViewModelPropertyName; PropertyName = dynamicPropertyIndexViewModel.PropertyName; }
public void Build(DynamicPropertyMetadata dynamicPropertyMetadata, DynamicPropertyIndexViewModel dynamicPropertyIndexViewModel, dynamic item) { if (dynamicPropertyMetadata.IsDynamicCollection) { //view model instructions for collection with dynamicdisplayhyperlink var dynamicHyperlinkViewModel = new DynamicEditorHyperlinkViewModel("View " + dynamicPropertyMetadata.DisplayName, dynamicPropertyMetadata.TypeName, "Index"); ////ToDo: Need to review this. It assumes FK follows a certain naming convention. FK must have name of related type var fkPropertyName = ((DynamicCollectionEntityPropertyMetadata)dynamicPropertyMetadata).ForiegnKeyPropertyName; dynamicHyperlinkViewModel.RouteValueDictionaryWrapper.SetValue(fkPropertyName, dynamicPropertyMetadata.DynamicEntityMetadata.KeyProperty.GetValueFunction(item)); dynamicPropertyIndexViewModel.DynamicEditorHyperlinkViewModel = dynamicHyperlinkViewModel; } else if (dynamicPropertyMetadata is DynamicForiegnKeyPropertyMetadata) { var dataIsNull = false; var dynamicForiegnKeyPropertyMetadata = ((DynamicForiegnKeyPropertyMetadata)dynamicPropertyMetadata); var dynamicEntity = dynamicForiegnKeyPropertyMetadata.ComplexEntityPropertyMetadata.GetValueFunction(item); if (dynamicEntity == null) { if (dynamicForiegnKeyPropertyMetadata.IsNullableType) { dataIsNull = true; } else { throw new Exception("DynamicMVC cannot display the default value for " + dynamicPropertyMetadata.PropertyName + " because the DynamicEntity is not loaded. Please make sure you are loading the " + dynamicPropertyMetadata.PropertyName + " in your query."); } } if (dataIsNull) { dynamicPropertyIndexViewModel.DynamicEditorHyperlinkViewModel = null; } else { var displayValue = ((DynamicForiegnKeyPropertyMetadata)dynamicPropertyMetadata).ComplexDynamicEntityMetadata.DefaultProperty.GetValueFunction(dynamicEntity); var dynamicHyperlinkViewModel = new DynamicEditorHyperlinkViewModel(displayValue.ToString(), ((DynamicForiegnKeyPropertyMetadata)dynamicPropertyMetadata).ComplexDynamicEntityMetadata.TypeName, "Details"); dynamicHyperlinkViewModel.RouteValueDictionaryWrapper.SetValue("Id", ((DynamicForiegnKeyPropertyMetadata)dynamicPropertyMetadata).ComplexDynamicEntityMetadata.KeyProperty.GetValueFunction(dynamicEntity)); dynamicPropertyIndexViewModel.DynamicEditorHyperlinkViewModel = dynamicHyperlinkViewModel; } dynamicPropertyIndexViewModel.DisplayName = ((DynamicForiegnKeyPropertyMetadata)dynamicPropertyMetadata).ComplexEntityPropertyMetadata.PropertyName; } }