/// <summary> /// Same method ("/user/index/"), but this one is only called /// from POST requests. /// </summary> /// <returns></returns> public IActionResult IndexPost() { // This is how easy a user is filled with info from a form: User user = new User(); PropertyAssigner.Assign(user, Parameters); // Save object in your database. return(Redirect("/user/index/")); }
public void Test() { var user = new User(); ParameterCollection col = new ParameterCollection { { "Name", "Jonas" }, { "Age", "17" } }; PropertyAssigner.Assign(user, col); Assert.Equal("Jonas", user.Name); Assert.Equal(17, user.Age); }
private ElementCompileTreeNode HandleProducerElement(ElementCompileTreeNode element, List <PropertyCompileTreeNode> newProperties, string defaultOverloadPropertyName) { PropertyAssigner.AssignPropertiesToProducer(element, _compileContext); string replacingPropertyName = CompilerGlobals.DefaultPropertyName; if (defaultOverloadPropertyName != null) { replacingPropertyName = defaultOverloadPropertyName; } var replacingProperty = new PropertyCompileTreeNode(replacingPropertyName, element.XmlSourceNodeInformation); object result = ProducerMediatorPluginFacade.EvaluateProducer(element.XmlSourceNodeInformation.NamespaceURI, element.Producer); if (result is BindingProducer) { var bindingProducer = (BindingProducer)result; if (string.IsNullOrEmpty(bindingProducer.name)) { throw new FormCompileException("A binding declaraions is missing its name attribute", element.XmlSourceNodeInformation); } if (!_compileContext.RegistarBindingName(bindingProducer.name)) { throw new FormCompileException(string.Format("Name binding name {0} is used twice which is not allowed", bindingProducer.name), element.XmlSourceNodeInformation); } //if (_compileContext.GetBindingObject(bindingProducer.name) == null && !bindingProducer.optional) //{ // throw new FormCompileException(string.Format("The non optional binding {0} is missing its binding value", bindingProducer.name), element.XmlSourceNodeInformation); //} Type type = TypeManager.GetType(bindingProducer.type); _compileContext.SetBindingType(bindingProducer.name, type); } else if (_withDebug && result is IUiControl) { IUiControl uiControl = result as IUiControl; string debugControlNamespace; string debugControlName; UiControlFactoryPluginFacade.GetDebugControlName(_compileContext.CurrentChannel, out debugControlNamespace, out debugControlName); DebugUiControl debug = ProducerMediatorPluginFacade.CreateProducer(_compileContext.CurrentChannel, debugControlNamespace, debugControlName) as DebugUiControl; debug.UiControlID = _compileContext.GetNextDebugControlId; debug.UiControl = uiControl; result = debug; debug.UiControlID = uiControl.UiControlID; debug.TagName = element.XmlSourceNodeInformation.TagName; debug.SourceElementXPath = element.XmlSourceNodeInformation.XPath; foreach (CompileContext.IRebinding rd in _compileContext.Rebindings) { if (ReferenceEquals(uiControl, rd.SourceProducer)) { debug.Bindings.Add(new DebugUiControl.BindingInformation( rd.BindingObjectName, rd.DestinationObjectType, rd.PropertyName)); } } } replacingProperty.Value = result; newProperties.Add(replacingProperty); return(null); }