/// <summary> /// 29 March 2014 /// Jonathan Sanborn /// Saves the passed in student to the users.xml file /// /// 30 March 2014 /// moved xml generation to the user object /// </summary> /// <param name="user">The new user to create in the xml file</param> public void SaveNewUser(IXMLnode user) { string fileName = Path.Combine(filePath, Properties.Settings.Default.usersFilename); try { XDocument userFile = OpenFile(fileName, MMFileType.User); if (userFile != null) { userFile.Element("Users").Add(user.GetXMLNode()); userFile.Save(fileName); } } catch (FileNotFoundException ex) { System.Diagnostics.Debug.Write(ex.Message); } }
/// <summary> /// 30 March 2014 /// Jonathan Sanborn /// /// Updates the passed in user in the xml file /// </summary> /// <param name="user">the user to update</param> public void UpdateUser(IXMLnode user) { string fileName = Path.Combine(filePath, Properties.Settings.Default.usersFilename); try { XDocument userFile = OpenFile(fileName, MMFileType.User); if (userFile != null) { try { userFile.Descendants("User").First(s => s.Element("ID").Value == user.ID).ReplaceWith(user.GetXMLNode()); userFile.Save(fileName); } catch (ArgumentNullException ex) { System.Diagnostics.Debug.Write(DateTime.Now.ToString() + " UpdateUser failed null referance.\n" + ex.Message); } catch (InvalidOperationException ex) { System.Diagnostics.Debug.Write(DateTime.Now.ToString() + " UpdateUser failed Invalid Operation.\n" + ex.Message); } } } catch (FileNotFoundException ex) { System.Diagnostics.Debug.Write(ex.Message); } }
/// <summary> /// 29 March 2014 /// Jonathan Sanborn /// Saves the passed in student to the users.xml file /// /// 30 March 2014 /// moved xml generation to the user object /// </summary> /// <param name="user">The new user to create in the xml file</param> public void SaveNewUser(IXMLnode user) { string fileName = Path.Combine(filePath, Properties.Settings.Default.usersFilename); try { XDocument userFile = OpenFile(fileName, MMFileType.User); if (userFile != null) { userFile.Element("Users").Add(user.GetXMLNode()); userFile.Save(fileName); } } catch (FileNotFoundException ex) { System.Diagnostics.Debug.Write(ex.Message); } }
/// <summary> /// 30 March 2014 /// Jonathan Sanborn /// /// Updates the passed in user in the xml file /// </summary> /// <param name="user">the user to update</param> public void UpdateUser(IXMLnode user) { string fileName = Path.Combine(filePath, Properties.Settings.Default.usersFilename); try { XDocument userFile = OpenFile(fileName, MMFileType.User); if (userFile != null) { try { userFile.Descendants("User").First(s => s.Element("ID").Value == user.ID).ReplaceWith(user.GetXMLNode()); userFile.Save(fileName); } catch (ArgumentNullException ex) { System.Diagnostics.Debug.Write(DateTime.Now.ToString() + " UpdateUser failed null referance.\n" + ex.Message); } catch (InvalidOperationException ex) { System.Diagnostics.Debug.Write(DateTime.Now.ToString() + " UpdateUser failed Invalid Operation.\n" + ex.Message); } } } catch (FileNotFoundException ex) { System.Diagnostics.Debug.Write(ex.Message); } }