public void AddChild(Child child) { if (!idCheck(child.ID)) { Children.Add(child.toXML()); SaveChildren(); } else { throw new Exception("ID already exists..."); } }
/// <summary> /// updates child info /// </summary> /// <param name="child"></param> public void updateChild(Child child) { XElement childElement = (from c in DataSourceXml.Children.Elements() where Convert.ToInt32(c.Element("id").Value) == child.id select c).FirstOrDefault(); if (childElement != null) { childElement.ReplaceWith(child.toXML()); DataSourceXml.SaveChildren(); } else { throw new Exception("the child is not in the system.\n"); } }
/// <summary> /// adds child to list /// </summary> /// <param name="child"></param> public void addChild(Child child) { var temp = (from c in DataSourceXml.Children.Elements() where Convert.ToInt32(c.Element("id").Value) == child.id select c).FirstOrDefault(); if (temp == null) { DataSourceXml.Children.Add(child.toXML()); DataSourceXml.SaveChildren(); } else { throw new Exception("you are trying to add a existing child.\n"); } }
public void updateChild(Child thisChild) // is XML { XElement childElement = (from n in XML_Source.Nannys.Elements() where Convert.ToInt32(n.Element("id").Value) == thisChild._childID select n).FirstOrDefault(); if (childElement != null) { childElement.Remove(); XML_Source.Children.Add(thisChild.toXML()); XML_Source.SaveChildren(); } else { throw new Exception("the child does not exist in the system."); } }
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 UpdateChild(Child c) { XElement updateChild = (from child in Children.Elements() where Convert.ToInt32(child.Element("ID").Value) == c.ID select child).FirstOrDefault(); if (updateChild == null) { throw new Exception("No child with the same id..."); } foreach (var xElement in c.toXML().Elements()) { updateChild.Element(xElement.Name).Value = xElement.Value; } SaveChildren(); }
public void addChild(Child thisKid) // is XML { var index = (from n in XML_Source.Children.Elements() where Convert.ToInt64(n.Element("id").Value) == thisKid._childID select n).FirstOrDefault(); if (index != null) { throw new Exception("Child already exists in the system"); } //var momExist = (from n in XML_Source.Mothers.Elements() // where Convert.ToInt64(n.Element("id").Value) == thisKid._momID // select n).FirstOrDefault(); //if (momExist != null) //{ // throw new Exception("Mom's ID doesn't exist"); //} else { XML_Source.Children.Add(thisKid.toXML()); XML_Source.SaveChildren(); } //var childID = thisKid._childID; // add after XML database is added //var momHasThisID = DataSource.motherList.Any // (c => c._momID == childID); //if(momHasThisID) //throw new Exception("we have a mom with same ID!"); //var thisMom = thisKid._momID; //var momExist = DataSource.motherList.Any // (c => c._momID == thisMom); }