//--------------menage children----------------// /// <summary> /// adds a child to the data base /// Exception: /// there is are the same Id in the data base. /// </summary> /// <param name="child">child object to add </param> public void addChild(Child child) { if (DataSourceXml.ChildRoot.Elements().Any(x => (Convert.ToInt32(x.Element("Id").Value)) == child.Id)) { throw new DALException("There is the same child id alredy"); } DataSourceXml.ChildRoot.Add(child.Clone().ChildToXML()); DataSourceXml.saveChildren(); }
/// <summary> /// delete a Child from the data base /// </summary> /// <param name="id">childs id to remove</param> public void removeChild(int id) { XElement result = (from child in DataSourceXml.ChildRoot.Elements() where Convert.ToInt32(child.Element("Id").Value) == id select child).FirstOrDefault(); if (result != null) { result.Remove(); DataSourceXml.saveChildren(); } else { throw new DALException("ERROR: There is no Child with this id to remove"); } }