/// <summary> /// Save an answer collection. Also save its title and description. /// </summary> /// <param name="ansColl">The answer collection to save.</param> /// <param name="newTitle">The answer collection title to save.</param> /// <param name="newDescription">The answer collection description to save.</param> public static void SaveAnswers(HotDocs.Sdk.AnswerCollection ansColl, string newTitle, string newDescription) { string answerPath = ansColl.FilePath; string answerFileName = Path.GetFileName(answerPath); using (SamplePortal.Data.Answers answers = new SamplePortal.Data.Answers()) { if (!String.IsNullOrEmpty(ansColl.FilePath)) //If this assembly began with an answer file on the server { System.Data.DataView ansData = answers.SelectFile(answerFileName); if (ansData.Count > 0 && ansData[0]["Title"].ToString() == newTitle) //If the title did not change { //Update the existing entry. ansColl.WriteFile(false); answers.UpdateAnswerFile(answerFileName, newTitle, newDescription); } else { //Create a new entry and answer set. string newfname = Util.MakeTempFilename(".anx"); ansColl.WriteFile(Path.Combine(Settings.AnswerPath, newfname), false); answers.InsertNewAnswerFile(newfname, newTitle, newDescription); } } else //If this assembly began with a new or uploaded answer file { //Create a new answer file. string newfname = Util.MakeTempFilename(".anx"); ansColl.WriteFile(Path.Combine(Util.SafeDir(Settings.AnswerPath), newfname), false); //Create a new entry. answers.InsertNewAnswerFile(newfname, newTitle, newDescription); } } }
/// <summary> /// Save an answer collection. Also save its title and description. /// </summary> /// <param name="ansColl">The answer collection to save.</param> /// <param name="newTitle">The answer collection title to save.</param> /// <param name="newDescription">The answer collection description to save.</param> public static void SaveAnswers(HotDocs.Sdk.AnswerCollection ansColl, string newTitle, string newDescription) { string answerPath = ansColl.FilePath; string answerFileName = Path.GetFileName(answerPath); using (SamplePortal.Data.Answers answers = new SamplePortal.Data.Answers()) { if (!String.IsNullOrEmpty(ansColl.FilePath))//If this assembly began with an answer file on the server { System.Data.DataView ansData = answers.SelectFile(answerFileName); if (ansData.Count > 0 && ansData[0]["Title"].ToString() == newTitle)//If the title did not change { //Update the existing entry. ansColl.WriteFile(false); answers.UpdateAnswerFile(answerFileName, newTitle, newDescription); } else { //Create a new entry and answer set. string newfname = Util.MakeTempFilename(".anx"); ansColl.WriteFile(Path.Combine(Settings.AnswerPath, newfname), false); answers.InsertNewAnswerFile(newfname, newTitle, newDescription); } } else//If this assembly began with a new or uploaded answer file { //Create a new answer file. string newfname = Util.MakeTempFilename(".anx"); ansColl.WriteFile(Path.Combine(Util.SafeDir(Settings.AnswerPath), newfname), false); //Create a new entry. answers.InsertNewAnswerFile(newfname, newTitle, newDescription); } } }