/// <summary> /// Adds a newly created user to the list. /// </summary> public void AddUser(User user) { if (user.Id > MaxId) { MaxId = user.Id; } users.Add(user); links.Add(user.Id, users.Count - 1); links.Add(user.Name, users.Count - 1); //adds xml code XElement userXmlCode = new XElement("user"); XElement idXml = new XElement("id"); idXml.Add(user.Id); XElement nameXml = new XElement("name"); nameXml.Add(user.Name); userXmlCode.Add(idXml, nameXml); xml.Add(userXmlCode); //write to disk SaveToFile("Profiles\\" + UsersList.XmlFileName); }
/// <summary> /// Translates the xml code into an users list. /// </summary> private void ParseXml() { foreach (XElement user in xml.Elements("user")) { int id = Convert.ToInt32(user.Element("id").Value); if (id > MaxId) { MaxId = id; } string name = user.Element("name").Value; User newUser = new User(id, name); users.Add(newUser); links.Add(newUser.Id, users.Count - 1); links.Add(newUser.Name, users.Count - 1); } }