public YuzuFormViewModel CreateForGridItem <C, M>(C c, List <object> formFields, Expression <Func <C, bool> > isSuccess, Expression <Func <C, ActionResult> > getContentFromProperty, Expression <Func <M, GridDataModel> > gridProperty, Expression <Func <C, ActionResult> > handler = null, string template = null) where C : Controller { var model = new YuzuFormViewModel(); var content = umbracoContext.GetGridFormForEndpoint(getContentFromProperty, gridProperty); if (isSuccess.Compile()(c)) { model.Form = Success(content.Value <string>(CompletedTitle), content.Value <string>(CompletedBodyText)); model.Form.ActionLinks = mapper.Map <List <vmBlock_DataLink> >(content.Value <IEnumerable <Link> >(CompletedActionLinks)); } else { model.Form = Form(content.Value <string>(Title), content.Value <string>(SubmitButtonText), formFields); model.Form.ActionLinks = mapper.Map <List <vmBlock_DataLink> >(content.Value <IEnumerable <Link> >(ActionLinks)); } if (handler != null) { model.AddHandler(handler); } if (!string.IsNullOrEmpty(template)) { model.Template = template; } return(model); }
public static void AddHandler <C>(this YuzuFormViewModel formBuilder, Expression <Func <C, ActionResult> > actionLambda) { Type type = typeof(C); var methodName = actionLambda.GetMemberName(); formBuilder.Controller = type; formBuilder.Action = methodName; }
public static void AddDataAppSettings(this YuzuFormViewModel model, string key, object value) { var keyName = $"data-{key}"; var strValue = JsonConvert.SerializeObject(value); if (model.HtmlFormAttributes.ContainsKey(keyName)) { model.HtmlFormAttributes[keyName] = strValue; } else { model.HtmlFormAttributes.Add(keyName, strValue); } }