public ActionResult DeleteForm(ConsentFormModel model) { // For forms only soft delete to retain data. model.Deleted = true; _databaseService.DeleteConsentForm(model); return(RedirectToRoute("ManageForms")); }
/// <summary> /// Run a query to get a form by ID /// </summary> /// <param name="FormID">int - </param> public ConsentFormModel GetFormByID(int FormID) { var form = new ConsentFormModel(); using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["PhotoConsentDB"].ToString())) { cn.Open(); var sql = string.Format("SELECT * FROM ConsentForms WHERE [FormID] = {0}", FormID); SqlCommand sqlCommand = new SqlCommand(sql, cn); SqlDataReader reader = sqlCommand.ExecuteReader(); while (reader.Read()) { var model = new ConsentFormModel(); model.ConsentGiven = (bool)reader["ConsentGiven"]; model.CreatedBy = (string)reader["CreatedBy"]; model.DateCreated = (string)reader["DateCreated"]; model.FormID = (int)reader["FormID"]; model.GUID = Guid.Parse(reader["GUID"].ToString()); model.Deleted = (bool)reader["Deleted"]; model.DateSubmitted = reader["DateSubmitted"] == DBNull.Value ? "" : (string)reader["DateSubmitted"]; model.Notes = reader["Notes"] == DBNull.Value ? "" : (string)reader["Notes"]; model.ProjectName = reader["ProjectName"] == DBNull.Value ? "" : (string)reader["ProjectName"]; model.PaymoNumber = reader["PaymoNumber"] == DBNull.Value ? "" : (string)reader["PaymoNumber"]; form = model; } cn.Close(); } return(form); }
public ActionResult CreateForm(ConsentFormModel model) { model.DateCreated = string.Format("{0} {1}:{2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), DateTime.Now.Second); model.ConsentGiven = false; model.GUID = Guid.NewGuid(); model.Deleted = false; _databaseService.InsertConsentForm(model); // Get the form ID of the newly created form by the GUID just created. // use the form id to redirect the user to the forms view. var FormID = _databaseService.GetFormIDByGuid(model.GUID); return(RedirectToRoute("ViewForm", new { ID = FormID })); }
public ActionResult Index() { // In case this is the first time the application has been set up and the database is new. // Ensure the master admin form is present. var AdminForm = _databaseService.GetFormByID(1); if (AdminForm == null) { AdminForm = new ConsentFormModel(); AdminForm.Notes = "[DO NOT DELETE]"; AdminForm.ProjectName = "Master Form"; AdminForm.CreatedBy = "Admin"; AdminForm.GUID = Guid.Parse("00000000-0000-0000-0000-000000000000"); AdminForm.Deleted = true; AdminForm.DateCreated = string.Format("{0} {1}:{2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), DateTime.Now.Second); AdminForm.ConsentGiven = false; _databaseService.InsertConsentForm(AdminForm); } return(View()); }
public ActionResult EditForm(ConsentFormModel model) { _databaseService.UpdateConsentForm(model); return(RedirectToRoute("ViewForm", new { ID = model.FormID })); }
public void DeleteConsentForm(ConsentFormModel model) { _db.Execute("EXEC DeleteConsentForm @FormID, @Deleted", new { model.FormID, model.Deleted }); }
public void UpdateConsentForm(ConsentFormModel model) { _db.Execute("EXEC UpdateConsentForm @CreatedBy, @ProjectName, @Notes, @FormID, @ConsentGiven, @DateSubmitted, @PaymoNumber", new { model.CreatedBy, model.ProjectName, model.Notes, model.FormID, model.ConsentGiven, model.DateSubmitted, model.PaymoNumber }); }
/// <summary> /// Run SP to input the consent form into the database /// </summary> /// <param name="model">ConsentFormModel - </param> public void InsertConsentForm(ConsentFormModel model) { _db.Execute("EXEC InsertConsentForm @DateCreated, @CreatedBy, @ProjectName, @DateSubmitted, @ConsentGiven, @Notes, @GUID, @Deleted, @PaymoNumber", new { model.DateCreated, model.CreatedBy, model.ProjectName, model.DateSubmitted, model.ConsentGiven, model.Notes, model.GUID, model.Deleted, model.PaymoNumber }); }