public void AddChild(Child child) { // Searching for the child ID in the children XML file (returns 0 if not found) int temp = (from n in DataSourceXml.Children.Elements() where int.Parse(n.Element("Id").Value) == child.Id select int.Parse(n.Element("Id").Value)).FirstOrDefault(); if (temp != 0) { throw new Exception("ERROR: The child with id: " + child.Id + " already exist in the database !!!"); } else { DataSourceXml.Children.Add(child.toXML()); DataSourceXml.SaveInChildren(); } }
public void RemoveChild(int childId) { // Searching for the child instance in the children XML file (returns null if not found) XElement childToRemove = (from n in DataSourceXml.Children.Elements() where int.Parse(n.Element("Id").Value) == childId select n).FirstOrDefault(); if (childToRemove == null) { throw new Exception("ERROR: The child with id: " + childId + " not exist in the database !!!"); } else { childToRemove.Remove(); DataSourceXml.SaveInChildren(); } }