public void AddNanny(Nanny nanny) { if (!idCheck(nanny.ID)) { Nannies.Add(nanny.toXML()); SaveNannies(); } else { throw new Exception("ID already exists..."); } }
/// <summary> /// gets a nanny from UI and updates the information in the DS /// </summary> /// <param name="nanny"></param> public void updateNanny(Nanny nanny) { XElement nannyElement = (from n in DS.DataSourceXml.Nannys.Elements() where Convert.ToInt32(n.Element("id").Value) == nanny.id select n).FirstOrDefault(); if (nannyElement != null) { nannyElement.ReplaceWith(nanny.toXML()); DataSourceXml.SaveNannys(); } else { throw new Exception("the nanny is not in the system.\n"); } }
/// <summary> /// checks if nanny exists in DS and then adds to DS /// </summary> /// <param name="nanny"></param> public void addNanny(Nanny nanny) { var temp = (from n in DataSourceXml.Nannys.Elements() where Convert.ToInt32(n.Element("id").Value) == nanny.id select n).FirstOrDefault(); if (temp == null) { DataSourceXml.Nannys.Add(nanny.toXML()); DataSourceXml.SaveNannys(); } else { throw new Exception("nanny already in list\n"); } }
public void updateNanny(Nanny nanny) //is XML { XElement nannyElement = (from n in XML_Source.Nannys.Elements() where Convert.ToInt32(n.Element("id").Value) == nanny._nannyID select n).FirstOrDefault(); if (nannyElement != null) { nannyElement.Remove(); XML_Source.Nannys.Add(nanny.toXML()); XML_Source.SaveNannys(); } else { throw new Exception("the nanny is not in the system.\n"); } }
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(); } }
public void addNanny(Nanny thisNanny)//is XML { var index = (from n in XML_Source.Nannys.Elements() where Convert.ToInt64(n.Element("id").Value) == thisNanny._nannyID select n).FirstOrDefault(); // if FindIndex method returns -1 so thisNany doesn't exist if (index != null) { throw new Exception("ID already exist in the system"); } else { XML_Source.Nannys.Add(thisNanny.toXML()); XML_Source.SaveNannys(); } }