Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
 // 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;
     }
 }
Exemplo n.º 3
0
 // 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;
     }
 }
Exemplo n.º 4
0
 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" };
     }
 }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 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();
 }
Exemplo n.º 7
0
 public FormDataAdapter()
     : base()
 {
     this.InternalForm = new Form();
 }
Exemplo n.º 8
0
        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;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }