public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { FormInsertModel model = new FormInsertModel(); model.FormPublicIdentifier = (string)controllerContext.RouteData.Values["FormPublicIdentifier"]; model.FormTag = controllerContext.HttpContext.Request.Form["FormTag"]; model.Fields = new List <FieldInsertModel>(); string httpMethod = controllerContext.HttpContext.Request.HttpMethod; NameValueCollection form = httpMethod == "POST" ? controllerContext.HttpContext.Request.Form : controllerContext.HttpContext.Request.QueryString; foreach (string key in form.AllKeys) { if (key.Length == 13 && !key.StartsWith("_") && !String.IsNullOrEmpty(key) && !String.IsNullOrWhiteSpace(key) && !NotFieldIdentifiers.Contains(key)) { model.Fields.Add(new FieldInsertModel { PublicIdentifier = key, Value = form[key] }); } } return(model); }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { FormInsertModel model = new FormInsertModel(); model.FormPublicIdentifier = (string)controllerContext.RouteData.Values["FormPublicIdentifier"]; model.FormTag = controllerContext.HttpContext.Request.Form["FormTag"]; model.Fields = new List<FieldInsertModel>(); string httpMethod = controllerContext.HttpContext.Request.HttpMethod; NameValueCollection form = httpMethod == "POST" ? controllerContext.HttpContext.Request.Form : controllerContext.HttpContext.Request.QueryString; foreach (string key in form.AllKeys) { if (key.Length == 13 && !key.StartsWith("_") && !String.IsNullOrEmpty(key) && !String.IsNullOrWhiteSpace(key) && !NotFieldIdentifiers.Contains(key)) { model.Fields.Add(new FieldInsertModel { PublicIdentifier = key, Value = form[key] }); } } return model; }
public ActionResult InsertFormData(FormInsertModel model) { List<InsertValidationModel> validation = new List<InsertValidationModel>(); IFormDataCreator creator = DataService.CreateForm(); SetPublicIdentifierStatus spi = creator.PublicIdentifier(model.FormPublicIdentifier); if (spi == SetPublicIdentifierStatus.NoSuchFormDefinition) validation.Add(new InsertValidationModel(null, "NoSuchFormDefinition")); if (!String.IsNullOrEmpty(model.ParentPublicIdentifier)) { SetParentDataStatus spd = creator.Parent(model.ParentPublicIdentifier); switch (spd) { case SetParentDataStatus.NoSuchFormData: validation.Add(new InsertValidationModel(null, "NoSuchFormData")); break; case SetParentDataStatus.NoSuchFormDefinition: validation.Add(new InsertValidationModel(null, "NoSuchFormDefinition")); break; } } creator.Tag(model.FormTag); FormDefinition form = FormService.Get(model.FormPublicIdentifier); foreach (FieldInsertModel field in model.Fields) { FieldDefinition def = form.Fields.FirstOrDefault(f => f.PublicIdentifier == field.PublicIdentifier); AddFieldStatus afs; if (def != null && def.FieldType == FieldType.FileField) { PostedFile file = files[field.Value]; if (file != null) { afs = creator.AddField(field.PublicIdentifier, file.Name, file.ContentType, file.Stream.ToArray()); files.Remove(field.Value); } else { afs = AddFieldStatus.IncorrectValue; } } else { afs = creator.AddFieldConvert(field.PublicIdentifier, field.Value); } switch (afs) { case AddFieldStatus.NoSuchFormDefinition: validation.Add(new InsertValidationModel(field.PublicIdentifier, "NoSuchFormDefinition")); break; case AddFieldStatus.NoSuchFieldDefinition: validation.Add(new InsertValidationModel(field.PublicIdentifier, "NoSuchFieldDefinition")); break; case AddFieldStatus.IncorrectFieldType: validation.Add(new InsertValidationModel(field.PublicIdentifier, "IncorrectFieldType")); break; case AddFieldStatus.IncorrectValue: validation.Add(new InsertValidationModel(field.PublicIdentifier, "IncorrectValue")); break; } } //TODO: Handle reference field! if (validation.Count == 0) { CreateFormDataStatus status = creator.Save(); switch (status) { case CreateFormDataStatus.InvalidCreator: validation.Add(new InsertValidationModel(null, "InvalidCreator")); break; } } if (validation.Count > 0) { //Response.StatusCode = 406; return JsonP(new { Errors = validation }); } DataService = DependencyResolver.Current.GetService<IFormDataService>(); //TODO: Never mind! 'Hack' for creating new DataContext return GetFormData(model.FormPublicIdentifier, 1, 0); }