public virtual async Task <ActionResult> Edit(dynamic id, FormCollection formCollection, string submitType, string returnUrl) { id = ParseKeyType(id); var model = _dynamicRepository.GetItem(EntityType, KeyName, id, DynamicEntityMetadata.InstanceIncludes().ToArray()); var viewModel = DynamicEditViewModelBuilder.Build(DynamicEntityMetadata, model, returnUrl); if (await TryUpdateModelAsync <DynamicCreateViewModel>(viewModel.Item, "Item")) { var dynamicOperation = DynamicEntityMetadata.GetDynamicOperation(TemplateTypeEnum.Edit, submitType); dynamicOperation.PerformPreSaveOperation(id, formCollection, model, ref returnUrl, TempData, ViewData); if (dynamicOperation.PersistModel) { EditItem(model); } dynamicOperation.PeformPostSaveOperation(id, formCollection, model, ref returnUrl, TempData, ViewData); if (dynamicOperation.ReturnSucessfulRedirect) { return(ReturnSuccessfulRedirect(returnUrl, model)); } } return(View("DynamicEdit", viewModel)); }
public string GetForiegnKeyNameByCollectionProperty(DynamicEntityMetadata dynamicEntityMetadata, string typeName, DynamicCollectionEntityPropertyMetadata dynamicCollectionEntityPropertyMetadata) { if (dynamicCollectionEntityPropertyMetadata.InverseProperty == null) { var complexProperties = dynamicEntityMetadata.DynamicPropertyMetadatas.Where(x => x.TypeName() == typeName).ToList(); if (complexProperties.Count == 1) { return(_namingConventionManager.GetForiegnKeyByComplexProperty(dynamicEntityMetadata.TypeName(), complexProperties.First().PropertyName())); } if (complexProperties.Count == 0) { throw new Exception("GetForiegnKeyNameByCollectionProperty could not find complex property for " + dynamicCollectionEntityPropertyMetadata.PropertyName() + " inside " + typeName); } else { throw new Exception("GetForiegnKeyNameByCollectionProperty could not find complex property for " + dynamicCollectionEntityPropertyMetadata.PropertyName() + " because two or more " + typeName + " exists"); } } else { var fkName = _namingConventionManager.GetForiegnKeyByComplexProperty(dynamicEntityMetadata.TypeName(), dynamicCollectionEntityPropertyMetadata.InverseProperty); if (dynamicEntityMetadata.DynamicPropertyMetadatas.All(x => x.PropertyName() != fkName)) { throw new Exception("GetForiegnKeyNameByCollectionProperty could not find inverse property for " + dynamicCollectionEntityPropertyMetadata.InverseProperty); } return(fkName); } }
public DynamicPropertyMetadata GetCollectionProperty(DynamicEntityMetadata dynamicEntityMetadata, DynamicPropertyMetadata dynamicPropertyMetadata) { var collectionProperties = dynamicEntityMetadata.DynamicPropertyMetadatas.Where(x => x.IsDynamicCollection() && x.TypeName() == dynamicEntityMetadata.TypeName()).Select(x => (DynamicCollectionEntityPropertyMetadata)x).ToList(); if (collectionProperties.Count == 0) { return(null); } if (collectionProperties.Count == 1) { return(collectionProperties.First()); } collectionProperties = collectionProperties.Where(x => x.InverseProperty != null && x.InverseProperty == dynamicPropertyMetadata.PropertyName()).ToList(); if (collectionProperties.Count == 1) { return(collectionProperties.First()); } if (collectionProperties.Count == 0) { return(null); } throw new Exception("Collection cannot be found in entity " + dynamicEntityMetadata.TypeName() + " for property " + dynamicPropertyMetadata.TypeName()); }
public void SetFilters(DynamicEntityMetadata dynamicEntityMetadata, IEnumerable <Func <IQueryable, IQueryable> > filters) { // ReSharper disable once PossibleMultipleEnumeration Filters = filters.ToList(); // ReSharper disable once PossibleMultipleEnumeration RecordCount = _dynamicRepository.GetRecordCount(dynamicEntityMetadata.EntityTypeFunction()(), filters); }
public IEnumerable GetItems(DynamicEntityMetadata dynamicEntityMetadata, RouteValueDictionaryWrapper routeValueDictionaryWrapper) { var page = int.Parse(routeValueDictionaryWrapper.GetValue("Page").ToString()); var pageSize = int.Parse(routeValueDictionaryWrapper.GetValue("PageSize").ToString()); return(_dynamicRepository.GetItems(dynamicEntityMetadata.EntityTypeFunction()(), Filters, page, pageSize, _requestManager.OrderBy(), dynamicEntityMetadata.ListIncludes().ToArray())); }
public DynamicIndexPageViewModel Build(DynamicEntityMetadata dynamicEntityMetadata) { var dynamicIndexPageViewModel = new DynamicIndexPageViewModel(); var routeValuesDictionary = _requestManager.QueryStringDictionary; _requestManager.CorrectQuerystringTypes(dynamicEntityMetadata); var dynamicFilterViewModels = _dynamicFilterManager.GetFilterPropertyViewModels(dynamicEntityMetadata, routeValuesDictionary); var filters = dynamicFilterViewModels.Select(x => (Func <IQueryable, IQueryable>)x.FilterModel.Filter).ToList(); _pagingManager.SetFilters(dynamicEntityMetadata, filters); _pagingManager.ValidatePagingParameters(routeValuesDictionary); var models = _pagingManager.GetItems(dynamicEntityMetadata, routeValuesDictionary); dynamicIndexPageViewModel.RouteValueDictionaryWrapper = routeValuesDictionary; dynamicIndexPageViewModel.RouteValueDictionaryWrapper.SetValue("ReturnUrl", _returnUrlManager.GetReturnUrl("Index", dynamicEntityMetadata.TypeName(), routeValuesDictionary, true)); dynamicIndexPageViewModel.NextClassName = _pagingManager.NextClassName(routeValuesDictionary); dynamicIndexPageViewModel.PreviousClassName = _pagingManager.PreviousClassName(routeValuesDictionary); dynamicIndexPageViewModel.PagingMessage = _pagingManager.PagingMessage(routeValuesDictionary); dynamicIndexPageViewModel.ShowCreate = dynamicEntityMetadata.ShowCreate(); dynamicIndexPageViewModel.ShowEdit = dynamicEntityMetadata.ShowEdit(); dynamicIndexPageViewModel.ShowDelete = dynamicEntityMetadata.ShowDelete(); dynamicIndexPageViewModel.ShowDetails = dynamicEntityMetadata.ShowDetails(); dynamicIndexPageViewModel.TypeName = dynamicEntityMetadata.TypeName(); dynamicIndexPageViewModel.DynamicPropertyIndexViewModels = GetDynamicPropertyViewModels(dynamicEntityMetadata, null).ToList(); var defaultpropertyName = dynamicEntityMetadata.DefaultProperty().PropertyName(); var defaultDynamicProperty = dynamicIndexPageViewModel.DynamicPropertyIndexViewModels.SingleOrDefault(x => x.PropertyName == defaultpropertyName); if (defaultDynamicProperty != null) { dynamicIndexPageViewModel.AllowSort = true; dynamicIndexPageViewModel.DefaultPropertyName = defaultpropertyName; dynamicIndexPageViewModel.DefaultPropertySortExpression = defaultDynamicProperty.SortExpression; } //table header items foreach (var dynamicPropertyIndexViewModel in dynamicIndexPageViewModel.DynamicPropertyIndexViewModels) { var dynamicTableHeaderViewModel = new DynamicTableHeaderViewModel(dynamicPropertyIndexViewModel, routeValuesDictionary, dynamicEntityMetadata.TypeName()); dynamicIndexPageViewModel.DynamicTableHeaderViewModels.Add(dynamicTableHeaderViewModel); } //new view model items foreach (var model in models) { var itemViewModel = BuildItemViewModel(dynamicEntityMetadata, routeValuesDictionary, model); dynamicIndexPageViewModel.DynamicIndexItemViewModels.Add(itemViewModel); var mobileItemViewModel = BuildMobileItemViewModel(dynamicEntityMetadata, routeValuesDictionary, model); dynamicIndexPageViewModel.DynamicIndexMobileItemViewModels.Add(mobileItemViewModel); } return(dynamicIndexPageViewModel); }
public DynamicIndexMobileItemViewModel BuildMobileItemViewModel(DynamicEntityMetadata dynamicEntityMetadata, RouteValueDictionaryWrapper routeValueDictionaryWrapper, dynamic item) { var dynamicIndexMobileItemViewModel = new DynamicIndexMobileItemViewModel(); dynamicIndexMobileItemViewModel.ShowDelete = dynamicEntityMetadata.ShowDelete(); dynamicIndexMobileItemViewModel.ShowEdit = dynamicEntityMetadata.ShowEdit(); dynamicIndexMobileItemViewModel.ShowDetails = dynamicEntityMetadata.ShowDetails(); dynamicIndexMobileItemViewModel.Item = item; IEnumerable <DynamicPropertyIndexViewModel> properties = GetDynamicPropertyViewModels(dynamicEntityMetadata, item); var defaultpropertyName = dynamicEntityMetadata.DefaultProperty().PropertyName(); var defaultDynamicProperty = properties.SingleOrDefault(x => x.PropertyName == defaultpropertyName); var entityName = dynamicEntityMetadata.TypeName(); foreach (var dynamicPropertyIndexViewModel in properties.Where(x => x.PropertyName != defaultpropertyName).ToList()) { dynamicIndexMobileItemViewModel.DynamicPropertyIndexViewModels.Add(dynamicPropertyIndexViewModel); } if (defaultDynamicProperty != null) { dynamicIndexMobileItemViewModel.DefaultDynamicPropertyViewModel = defaultDynamicProperty; } dynamicIndexMobileItemViewModel.EntityName = entityName; dynamicIndexMobileItemViewModel.TypeName = dynamicEntityMetadata.TypeName(); var rv = routeValueDictionaryWrapper.Clone(); rv.SetValue("Id", dynamicEntityMetadata.KeyProperty().GetValueFunction()(item).ToString()); dynamicIndexMobileItemViewModel.RouteValueDictionaryWrapper = rv; return(dynamicIndexMobileItemViewModel); }
public virtual ActionResult Edit(dynamic id, string returnUrl) { id = ParseKeyType(id); var model = _dynamicRepository.GetItem(EntityType, KeyName, id, DynamicEntityMetadata.InstanceIncludes().ToArray()); var viewModel = DynamicEditViewModelBuilder.Build(DynamicEntityMetadata, model, returnUrl); return(View("DynamicEdit", viewModel)); }
public dynamic ParseKeyType(dynamic id) { if (id.GetType() == typeof(String[])) //mvc model binder does not bind correctly with the dynamic data type in some cases { id = ((string[])id)[0]; } return(DynamicEntityMetadata.KeyProperty().ParseValue()(id.ToString())); }
public virtual ActionResult Delete(dynamic id, string returnUrl) { id = ParseKeyType(id); var model = _dynamicRepository.GetItem(EntityType, DynamicEntityMetadata.KeyProperty().PropertyName(), id); var viewModel = _dynamicDeleteViewModelBuilder.Build(DynamicEntityMetadata, model, returnUrl); return(View("DynamicDelete", viewModel)); }
public virtual ActionResult Create(string returnUrl) { dynamic createModel = DynamicEntityMetadata.CreateNewObject()(); UpdateModelAndClearModelState(createModel); var viewModel = DynamicCreateViewModelBuilder.Build(DynamicEntityMetadata, createModel, returnUrl); return(View("DynamicCreate", viewModel)); }
public string Validate(DynamicEntityMetadata dynamicEntityMetadata) { if (dynamicEntityMetadata.ScaffoldIndexProperties() == null) { return("ScaffoldIndexProperties should not be null for DynamicEntity " + dynamicEntityMetadata.TypeName()); } return(null); }
/// <summary> /// ScopeIdentity can be used to allow the create a ReturnUrl that includes the primary key for an entity that has not been created yet. /// You should use ScopeIdentity instead of the id value. /// For example, you could have a create actionlink that returns to the edit page once the entity has been created. /// </summary> /// <param name="returnUrl">The ReturnUrl that may contain ScopeIdentity</param> /// <param name="dynamicEntityMetadata"></param> /// <param name="createModel"></param> /// <returns></returns> public string ReplaceScopeIdentity(string returnUrl, DynamicEntityMetadata dynamicEntityMetadata, dynamic createModel) { if (returnUrl.Contains("ScopeIdentity")) { var keyValue = dynamicEntityMetadata.KeyProperty().GetValueFunction()(createModel); returnUrl = returnUrl.Replace("ScopeIdentity", keyValue.ToString()); } return(returnUrl); }
public DynamicDeleteViewModel Build(DynamicEntityMetadata dynamicEntityMetadata, dynamic deleteModel, string returnUrl) { var dynamicDeleteViewModel = new DynamicDeleteViewModel(); dynamicDeleteViewModel.TypeName = dynamicEntityMetadata.TypeName(); dynamicDeleteViewModel.Header = "Delete " + dynamicEntityMetadata.TypeName(); dynamicDeleteViewModel.ReturnUrl = returnUrl; return(dynamicDeleteViewModel); }
public virtual ActionResult Create(string returnUrl) { returnUrl = Url.Action("Details", "Order", new { id = "ScopeIdentity" }); dynamic createModel = DynamicEntityMetadata.CreateNewObject(); UpdateModelAndClearModelState(createModel); var viewModel = DynamicCreateViewModelBuilder.Build(DynamicEntityMetadata, createModel, returnUrl); return(View("DynamicCreate", viewModel)); }
/// <summary> /// Get properties to be scaffolded for this view. If view properties are passed in through the request, filter by them. /// </summary> /// <param name="dynamicEntityMetadata"></param> /// <returns></returns> public IEnumerable <DynamicPropertyMetadata> GetViewProperties(DynamicEntityMetadata dynamicEntityMetadata) { var dynamicPropertyMetadatas = dynamicEntityMetadata.ScaffoldEditProperties(); var viewProperties = _requestManager.ViewProperties(); if (!string.IsNullOrWhiteSpace(viewProperties)) { dynamicPropertyMetadatas = _propertyFilterManager.FilterAndOrderProperties(dynamicPropertyMetadatas, viewProperties).ToList(); } return(dynamicPropertyMetadatas); }
/// <summary> /// Only returns filters that are currently applied for the given routevalueDictionary /// </summary> /// <param name="dynamicEntityMetadata"></param> /// <param name="routeValueDictionaryWrapper"></param> /// <returns></returns> public IEnumerable <IDynamicFilter> GetDynamicFilters(DynamicEntityMetadata dynamicEntityMetadata, RouteValueDictionaryWrapper routeValueDictionaryWrapper) { var result = new List <IDynamicFilter>(); var dynamicFilterViewModels = GetFilterPropertyViewModels(dynamicEntityMetadata, routeValueDictionaryWrapper); foreach (var dynamicPropertyViewModel in dynamicFilterViewModels) { var dynamicFilter = dynamicPropertyViewModel.FilterModel; //if (dynamicFilter.FilterIsApplied()) result.Add(dynamicFilter); } return(result); }
public IEnumerable <DynamicFilterViewModel> GetFilterPropertyViewModels(DynamicEntityMetadata dynamicEntityMetadata, RouteValueDictionaryWrapper routeValueDictionaryWrapper) { var dynamicFilterViewModels = new List <DynamicFilterViewModel>(); //add default filters foreach (var dynamicPropertyMetadata in dynamicEntityMetadata.DynamicPropertyMetadatas.Where(x => !x.IsDynamicCollection)) { if (dynamicPropertyMetadata.HasDynamicFilterUIAttribute) { continue; //explicit filters will be added later } if (dynamicPropertyMetadata is DynamicForiegnKeyPropertyMetadata && !dynamicPropertyMetadata.ListFilterIndexHide) { var dynamicPropertyViewModel = new DynamicFilterViewModel(dynamicPropertyMetadata); var dynamicForiegnKeyPropertyMetadata = ((DynamicForiegnKeyPropertyMetadata)dynamicPropertyMetadata); var dropdownType = dynamicForiegnKeyPropertyMetadata.ComplexDynamicEntityMetadata.EntityType; if (_dynamicRepository.GetItemsCount(dropdownType) > _dynamicMvcManager.Options.DynamicDropDownRecordLimit) { dynamicPropertyViewModel.DynamicFilterViewName = "DynamicFilterAutoComplete"; } else { dynamicPropertyViewModel.DynamicFilterViewName = "DynamicFilterDropDown"; } dynamicFilterViewModels.Add(dynamicPropertyViewModel); } } //add explicit filters foreach (var dynamicPropertyMetadata in dynamicEntityMetadata.DynamicPropertyMetadatas.Where(x => x.HasDynamicFilterUIAttribute)) { var dynamicFilterViewModel = new DynamicFilterViewModel(dynamicPropertyMetadata); var dynamicFilterUIHintAttribute = dynamicPropertyMetadata.GetDynamicFilterUIHintAttribute(); dynamicFilterViewModel.DynamicFilterViewName = dynamicFilterUIHintAttribute.DynamicFilterViewName; dynamicFilterViewModels.Add(dynamicFilterViewModel); } //add models for any filters foreach (var dynamicFilterViewModel in dynamicFilterViewModels) { var dynamicPropertyMetadata = dynamicEntityMetadata.DynamicPropertyMetadatas.Single(x => x.PropertyName == dynamicFilterViewModel.PropertyName); var dynamicFilter = _dynamicFilterFactory.GetDynamicFilter(dynamicFilterViewModel.DynamicFilterViewName, dynamicPropertyMetadata, routeValueDictionaryWrapper); dynamicFilterViewModel.FilterModel = dynamicFilter; if (dynamicPropertyMetadata.HasDynamicFilterUIAttribute) { dynamicFilterViewModel.FilterModel.Order = dynamicPropertyMetadata.GetDynamicFilterUIHintAttribute().Order; } } dynamicFilterViewModels = dynamicFilterViewModels.OrderBy(x => ((DynamicFilterBaseViewModel)x.FilterModel).Order).ToList(); return(dynamicFilterViewModels); }
public DynamicIndexViewModel Build(DynamicEntityMetadata dynamicEntityMetadata) { var dynamicIndexViewModel = new DynamicIndexViewModel(); var routeValueDictionary = _requestManager.QueryStringDictionary; _requestManager.CorrectQuerystringTypes(dynamicEntityMetadata); dynamicIndexViewModel.RouteValueDictionaryWrapper = routeValueDictionary; dynamicIndexViewModel.Header = dynamicEntityMetadata.IndexHeader(); dynamicIndexViewModel.TypeName = dynamicEntityMetadata.TypeName(); dynamicIndexViewModel.FilterMessage = _dynamicFilterManager.GetFilterMessage(dynamicEntityMetadata, routeValueDictionary); var filters = _dynamicFilterManager.GetFilterPropertyViewModels(dynamicEntityMetadata, routeValueDictionary).ToList(); dynamicIndexViewModel.DynamicIndexFiltersViewModel = new DynamicIndexFiltersViewModel(dynamicEntityMetadata.TypeName(), routeValueDictionary, filters); return(dynamicIndexViewModel); }
public string GetFilterMessage(DynamicEntityMetadata dynamicEntityMetadata, RouteValueDictionaryWrapper routeValueDictionaryWrapper) { var sb = new StringBuilder(); foreach (var filter in GetDynamicFilters(dynamicEntityMetadata, routeValueDictionaryWrapper)) { if (routeValueDictionaryWrapper.ContainsKey(filter.QueryStringName)) { if (sb.Length == 0) { sb.Append("Filtered By " + filter.PropertyName); } else { sb.Append(", " + filter.PropertyName); } } } return(sb.ToString()); }
public DynamicDetailsViewModel Build(DynamicEntityMetadata dynamicEntityMetadata, dynamic detailModel) { var dynamicDetailsViewModel = new DynamicDetailsViewModel(); dynamicDetailsViewModel.TypeName = dynamicEntityMetadata.TypeName; dynamicDetailsViewModel.Header = dynamicEntityMetadata.DetailsHeader; dynamicDetailsViewModel.Item = detailModel; foreach (var dynamicPropertyEditorViewModel in GetDynamicPropertyViewModels(dynamicEntityMetadata, detailModel)) { var dynamicEditorViewModel = new DynamicEditorViewModel(); dynamicEditorViewModel.ViewModelPropertyName = dynamicPropertyEditorViewModel.ViewModelPropertyName; dynamicEditorViewModel.DynamicEditorName = dynamicPropertyEditorViewModel.DynamicEditorName; dynamicEditorViewModel.DynamicPropertyEditorViewModel = dynamicPropertyEditorViewModel; dynamicDetailsViewModel.DynamicEditorViewModels.Add(dynamicEditorViewModel); } return(dynamicDetailsViewModel); }
public DynamicCreateViewModel Build(DynamicEntityMetadata dynamicEntityMetadata, dynamic createModel, string returnUrl) { var dynamicCreateViewModel = new DynamicCreateViewModel(); dynamicCreateViewModel.Header = dynamicEntityMetadata.CreateHeader(); dynamicCreateViewModel.TypeName = dynamicEntityMetadata.TypeName(); dynamicCreateViewModel.ReturnUrl = returnUrl; dynamicCreateViewModel.Item = createModel; dynamicCreateViewModel.DynamicUIMethods = dynamicEntityMetadata.GetDynamicMethods(TemplateTypeEnum.Create).ToList(); foreach (var dynamicPropertyEditorViewModel in GetDynamicPropertyViewModels(dynamicEntityMetadata, createModel)) { var dynamicEditorViewModel = new DynamicEditorViewModel(); dynamicEditorViewModel.ViewModelPropertyName = dynamicPropertyEditorViewModel.ViewModelPropertyName; dynamicEditorViewModel.DynamicEditorName = dynamicPropertyEditorViewModel.DynamicEditorName; dynamicEditorViewModel.DynamicPropertyEditorViewModel = dynamicPropertyEditorViewModel; dynamicCreateViewModel.DynamicEditorViewModels.Add(dynamicEditorViewModel); } return(dynamicCreateViewModel); }
public DynamicDetailsViewModel Build(DynamicEntityMetadata dynamicEntityMetadata, dynamic detailModel) { var dynamicDetailsViewModel = new DynamicDetailsViewModel(); dynamicDetailsViewModel.TypeName = dynamicEntityMetadata.TypeName(); dynamicDetailsViewModel.Header = dynamicEntityMetadata.DetailsHeader(); dynamicDetailsViewModel.Item = detailModel; dynamicDetailsViewModel.DynamicUIMethods = dynamicEntityMetadata.GetDynamicMethods(TemplateTypeEnum.Details).ToList(); foreach (var dynamicPropertyEditorViewModel in GetDynamicPropertyViewModels(dynamicEntityMetadata, detailModel)) { var dynamicEditorViewModel = new DynamicEditorViewModel(); dynamicEditorViewModel.ViewModelPropertyName = dynamicPropertyEditorViewModel.ViewModelPropertyName; dynamicEditorViewModel.DynamicEditorName = dynamicPropertyEditorViewModel.DynamicEditorName; dynamicEditorViewModel.DynamicPropertyEditorViewModel = dynamicPropertyEditorViewModel; dynamicDetailsViewModel.DynamicEditorViewModels.Add(dynamicEditorViewModel); } return(dynamicDetailsViewModel); }
public DynamicEditViewModel Build(DynamicEntityMetadata dynamicEntityMetadata, dynamic editModel, string returnUrl) { var dynamicEditViewModel = new DynamicEditViewModel(); dynamicEditViewModel.Header = dynamicEntityMetadata.EditHeader; dynamicEditViewModel.TypeName = dynamicEntityMetadata.TypeName; dynamicEditViewModel.ReturnUrl = returnUrl; dynamicEditViewModel.Item = editModel; foreach (var dynamicPropertyViewModel in GetDynamicPropertyViewModels(dynamicEntityMetadata, editModel)) { var dynamicEditorViewModel = new DynamicEditorViewModel(); dynamicEditorViewModel.ViewModelPropertyName = dynamicPropertyViewModel.ViewModelPropertyName; dynamicEditorViewModel.DynamicEditorName = dynamicPropertyViewModel.DynamicEditorName; dynamicEditorViewModel.DynamicPropertyEditorViewModel = dynamicPropertyViewModel; dynamicEditViewModel.DynamicEditorViewModels.Add(dynamicEditorViewModel); } return(dynamicEditViewModel); }
public void CorrectQuerystringTypes(DynamicEntityMetadata dynamicEntityMetadata) { if (!_correctedTypes) { foreach (var key in QueryStringDictionary.GetKeys()) { var property = dynamicEntityMetadata.DynamicPropertyMetadatas.SingleOrDefault(x => x.PropertyName() == key); if (property != null && property.IsSimple()) { var origonalValue = QueryStringDictionary.GetValue(key).ToString(); //There is an issue with html.checkbox helper. It sends down true,false when checked if (property.SimpleTypeEnum() == SimpleTypeEnum.Bool && origonalValue == "true,false") { origonalValue = "true"; } var parsedValue = property.ParseValue()(origonalValue); QueryStringDictionary.SetValue(key, parsedValue); } } _correctedTypes = true; } }
/// <summary> /// This is called on the create to load related entities /// </summary> /// <param name="dynamicEntityMetadata"></param> /// <param name="item"></param> /// <param name="dynamicRepository"></param> /// <param name="includes"></param> public void LoadCreateIncludes(DynamicEntityMetadata dynamicEntityMetadata, dynamic item, IDynamicRepository dynamicRepository, params string[] includes) { foreach (var include in includes.ToList()) { var currentInclude = include; string subinclude = null; if (currentInclude.Contains(".")) { var index = currentInclude.IndexOf('.'); subinclude = currentInclude.Substring(index + 1); currentInclude = include.Substring(0, index); } currentInclude = currentInclude.Trim(); var property = dynamicEntityMetadata.DynamicPropertyMetadatas.Single(x => x.PropertyName == currentInclude); if (property.IsDynamicCollection) { //its not possible to have a fk to this object b/c its not created yet } else if (property.IsDynamicEntity) { var typeName = property.TypeName; var dynamicMetadata = GetDynamicEntityMetadata(typeName); var id = ((DynamicComplexPropertyMetadata)property).DynamicForiegnKeyPropertyMetadata.GetValueFunction(item); var value = string.IsNullOrWhiteSpace(subinclude) ? dynamicRepository.GetItem(dynamicMetadata.EntityType, dynamicMetadata.KeyProperty.PropertyName, id) : dynamicRepository.GetItem(dynamicMetadata.EntityType, dynamicMetadata.KeyProperty.PropertyName, id, subinclude); property.SetValueAction(item, value); //Add item to the collection for this entity var collectionProperty = _navigationPropertyManager.GetCollectionProperty(dynamicEntityMetadata, property); if (collectionProperty != null) { var collection = collectionProperty.GetValueFunction(value); //Todo: throw exception here if collection is null collection.GetType().GetMethod("Add").Invoke(collection, new[] { item }); } } } }
public DynamicIndexItemViewModel BuildItemViewModel(DynamicEntityMetadata dynamicEntityMetadata, RouteValueDictionaryWrapper routeValueDictionaryWrapper, dynamic item) { var dynamicIndexItemViewModel = new DynamicIndexItemViewModel(); dynamicIndexItemViewModel.ShowDelete = dynamicEntityMetadata.ShowDelete(); dynamicIndexItemViewModel.ShowEdit = dynamicEntityMetadata.ShowEdit(); dynamicIndexItemViewModel.ShowDetails = dynamicEntityMetadata.ShowDetails(); dynamicIndexItemViewModel.Item = item; dynamicIndexItemViewModel.TypeName = dynamicEntityMetadata.TypeName(); var rv = routeValueDictionaryWrapper.Clone(); rv.SetValue("Id", dynamicEntityMetadata.KeyProperty().GetValueFunction()(item).ToString()); dynamicIndexItemViewModel.RouteValueDictionaryWrapper = rv; IEnumerable <DynamicPropertyIndexViewModel> properties = GetDynamicPropertyViewModels(dynamicEntityMetadata, item); foreach (var property in properties) { dynamicIndexItemViewModel.DynamicPropertyIndexViewModels.Add(property); } return(dynamicIndexItemViewModel); }
public async virtual Task <ActionResult> Create(FormCollection formCollection, string submitType, string returnUrl) { dynamic model = DynamicEntityMetadata.CreateNewObject()(); var viewModel = DynamicCreateViewModelBuilder.Build(DynamicEntityMetadata, model, returnUrl); if (await TryUpdateModelAsync <DynamicCreateViewModel>(viewModel.Item, "Item")) { var dynamicOperation = DynamicEntityMetadata.GetDynamicOperation(TemplateTypeEnum.Create, submitType); dynamicOperation.PerformPreSaveOperation(null, formCollection, model, ref returnUrl, TempData, ViewData); if (dynamicOperation.PersistModel) { CreateItem(model); } dynamicOperation.PeformPostSaveOperation(null, formCollection, model, ref returnUrl, TempData, ViewData); if (dynamicOperation.ReturnSucessfulRedirect) { return(ReturnSuccessfulRedirect(returnUrl, model)); } } return(View("DynamicCreate", viewModel)); }
public void CreateItem(dynamic createModel) { DynamicMVCContext.DynamicMvcManager.LoadCreateIncludes(DynamicEntityMetadata, createModel, _dynamicRepository, DynamicEntityMetadata.InstanceIncludes().ToArray()); _dynamicRepository.CreateItem(EntityType, createModel); }
public IEnumerable <DynamicPropertyEditorViewModel> GetDynamicPropertyViewModels(DynamicEntityMetadata dynamicEntityMetadata, dynamic item) { if (_dynamicPropertyEditorViewModels == null) { _dynamicPropertyEditorViewModels = new List <DynamicPropertyEditorViewModel>(); var viewProperties = GetViewProperties(dynamicEntityMetadata); viewProperties = viewProperties.Where(x => x.IsSimple()).ToList(); //this view only shows simple properties foreach (var dynamicPropertyMetadata in viewProperties) { var dynamicPropertyEditorViewModel = _dynamicPropertyViewModelBuilder.BuildDynamicPropertyEditorViewModelForEdit(dynamicPropertyMetadata); if (dynamicPropertyEditorViewModel != null) { //create model for editor if applicable IDynamicEditorModelBuilder dynamicEditorModelMaterializer = _dynamicEditorModelBuilders.SingleOrDefault(x => x.DynamicEditorName() == dynamicPropertyEditorViewModel.DynamicEditorName); if (dynamicEditorModelMaterializer != null) { dynamicEditorModelMaterializer.Build(dynamicPropertyMetadata, dynamicPropertyEditorViewModel, item); } _dynamicPropertyEditorViewModels.Add(dynamicPropertyEditorViewModel); } } } return(_dynamicPropertyEditorViewModels); }