public void RemoveNanny(int nannyId) { // Searching for the nanny instance in the nanny's XML file (returns null if not found) XElement nannyToRemove = (from n in DataSourceXml.Nannies.Elements() where int.Parse(n.Element("Id").Value) == nannyId select n).FirstOrDefault(); if (nannyToRemove == null) { throw new Exception("ERROR: The nanny with id: " + nannyId + " not exist in the database !!!"); } else { nannyToRemove.Remove(); DataSourceXml.SaveInNannies(); } }
public void AddNanny(Nanny nanny) { // Searching for the nanny ID in the nanny's XML file (returns 0 if not found) int temp = (from n in DataSourceXml.Nannies.Elements() where int.Parse(n.Element("Id").Value) == nanny.Id select int.Parse(n.Element("Id").Value)).FirstOrDefault(); if (temp != 0) { throw new Exception("ERROR: The nanny with id: " + nanny.Id + " already exist in the database !!!"); } else { DataSourceXml.Nannies.Add(nanny.toXML()); DataSourceXml.SaveInNannies(); } }