public ActionResult Create(Form Form) { try { // TODO: Add insert logic here if (Form != null) { try { Form.Save(); return RedirectToAction("Index"); } catch (Exception ex) { ViewBag.Error = ex.Message; } } else { ViewBag.Error = "No data was sent to the server."; } return View(); } catch { return View(); } }
// GET api/form/5 public Object Get(int id) { try { Form f = new Form(); f.Load(id, User); return f; } catch (Exception ex) { throw ex; } }
// GET api/form public Form Get(int? templateID = null) { if (templateID.HasValue) { Form f = new Form(); f.New(templateID.Value, User); return f; } else { return null; } }
public object Post(Form dataForm) { if (dataForm != null) { try { dataForm.Save(); return new { result = "success" }; } catch (Exception ex) { return new { result = "error", error = ex.Message }; } } else { return new { result = "error", error = "No data was passed to save" }; } }
public void SaveForm(Form Form) { ClearData(); comm.Parameters.AddWithValue("@TemplateID", Form.Template.ID); if (Form.ID.HasValue) { comm.CommandText = "UPDATE " + Config.TableNames["Forms"] + " SET TemplateID=@TemplateID WHERE ID=@ID"; comm.Parameters.AddWithValue("@ID",Form.ID); try { comm.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } } else { //TODO: add CreatedBy field once permissions and users are added to the system. comm.CommandText = "INSERT INTO " + Config.TableNames["Forms"] + " (TemplateID,CreatedDate) VALUES (@TemplateID,@CreatedDate); SELECT CAST(SCOPE_IDENTITY() as int);"; comm.Parameters.AddWithValue("@CreatedDate",DateTime.Now); try { int newID = (int)comm.ExecuteScalar(); Form.ID = newID; } catch (Exception ex) { throw ex; } } SaveValues(Form); }
public ActionResult Edit(Form Form) { if (Form != null) { try { Form.Save(); return RedirectToAction("Index"); } catch (Exception ex) { ViewBag.Error = ex.Message; } } else { ViewBag.Error = "No data was sent to the server."; } return View(); }
public FormDataAdapter() : base() { this.InternalForm = new Form(); }
private void SaveValues(Form form) { ClearData(); //TODO: DELETE values that no longer exist DELETE WHERE ID NOT IN (); foreach (Section sec in form.Sections) { foreach (Field field in sec.Fields) { field.SectionID = sec.ID; if (field.Type != "text") { foreach (Value val in field.Values) { if (val.Content != null) { val.FormID = form.ID; val.FieldID = field.ID; comm.Parameters.Clear(); comm.Parameters.AddWithValue("@Content", val.Content); if (val.ID.HasValue) { comm.CommandText = "UPDATE " + Config.TableNames["Values"] + " SET Content=@Content WHERE ID=@ID"; comm.Parameters.AddWithValue("@ID", val.ID); try { comm.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } } else { comm.Parameters.AddWithValue("@FormID", val.FormID); comm.Parameters.AddWithValue("@FieldID", val.FieldID); comm.Parameters.AddWithValue("@OptionID", val.OptionID.HasValue ? val.OptionID.Value.ToString() : ""); comm.CommandText = "INSERT INTO " + Config.TableNames["Values"] + " (FormID, FieldID, OptionID, Content) VALUES (@FormID, @FieldID, @OptionID, @Content); SELECT CAST(SCOPE_IDENTITY() as int);"; try { val.ID = (int)comm.ExecuteScalar(); } catch (Exception ex) { throw ex; } } } } } } } }