public static void DeleteStudent(StudentXml studentDelete) { XDocument studentDoc = GetXmlStudents(); studentDoc.Root.Elements().First(st => st.Attribute("Id").Value == studentDelete.ID.ToString()).Remove(); studentDoc.Save(@"Students.xml"); }
public static void UpdateStudent(StudentXml sx) { XDocument studentDoc = GetXmlStudents(); XElement studentToUpdate = studentDoc.Root.Elements().First(stf => stf.Attribute("Id").Value == sx.ID.ToString()); studentToUpdate.SetElementValue("FirstName", sx.FirstName); studentToUpdate.SetElementValue("Last", sx.LastName); studentToUpdate.SetElementValue("Age", sx.Age); studentToUpdate.SetElementValue("Gender", sx.Gender == 'm' ? 0 : 1); studentDoc.Save(@"Students.xml"); }
public static void InsertNewStudent(StudentXml sx) { XDocument studentDoc = GetXmlStudents(); studentDoc.Descendants("Students").First().Add(new XElement("Student", new XAttribute("Id", sx.ID), new XElement("FirstName", sx.FirstName), new XElement("Last", sx.LastName), new XElement("Age", sx.Age), new XElement("Gender", sx.Gender == 'm' ? 0 : 1))); studentDoc.Save(@"Students.xml"); }