public void addPass() { string firstCode = "1234"; XML_Source.Passwords.Add(firstCode.toXMLPassword()); XML_Source.SavePasswords(); }
public void deleteChild(long thisKid) // is XML { XElement index = (from n in XML_Source.Children.Elements() where Convert.ToInt64(n.Element("id").Value) == thisKid select n).FirstOrDefault(); if (index == null) { throw new Exception("Child doesn't exist in the system"); } // else // 1. delete all contracts with thisKid XElement ContractDelete = (from n in XML_Source.Contracts.Elements() where Convert.ToInt64(n.Element("id").Value) == thisKid select n).FirstOrDefault(); ContractDelete.Remove(); //DataSource.contractList.RemoveAll // (c => c._childID == thisKid); // 2. remove thisKid index.Remove(); // removes the kid XML_Source.SaveContracts(); }
public void addMother(Mother mother) //is XML { var temp = (from m in XML_Source.Mothers.Elements() where Convert.ToInt64(m.Element("id").Value) == mother._momID select m).FirstOrDefault(); if (temp != null) { throw new Exception("you are trying to add an existing mother.\n"); } TimeSpan totalWeeklyHours = new TimeSpan(); for (int i = 0; i < 6; i++) { totalWeeklyHours += (mother._endHour[i] - mother._startHour[i]); // totalWeeklyHours += (endHoure.Value - startHoure.Value); } mother._monthHours = ((totalWeeklyHours.Days * 24 + totalWeeklyHours.Hours + totalWeeklyHours.Minutes / 60.0) * 4); //dal.addMother(thisMom); // DataSource.motherList.Add(mother); XML_Source.Mothers.Add(mother.toXML()); XML_Source.SaveMothers(); }
public bool addEmployer(Employer e) { if (ElementIfExists(XML_Source.employerRoot, e.ID) != null) { throw new Exception(e.ID + " already exists in file"); } XML_Source.employerRoot.Add(createEmployerXElement(e)); XML_Source.SaveXML <Employer>(); return(true); }
public void deleteMother(long thisMom) //is XML { XElement motherElement = (from n in XML_Source.Mothers.Elements() where Convert.ToInt32(n.Element("id").Value) == thisMom select n).FirstOrDefault(); if (motherElement == null) { throw new Exception("you are trying to delete a mother that does not exist\n"); } // deleates childs that are related to the mother XElement ChildtDelete = (from n in XML_Source.Children.Elements() where Convert.ToInt64(n.Element("id").Value) == thisMom select n).FirstOrDefault(); if (ChildtDelete != null) { ChildtDelete.Remove(); } // deleates contracts that are related to the mother XElement ContractDelete = (from n in XML_Source.Contracts.Elements() where Convert.ToInt64(n.Element("id").Value) == thisMom select n).FirstOrDefault(); if (ContractDelete != null) { ContractDelete.Remove(); } motherElement.Remove(); XML_Source.SaveMothers(); ////else //// 1. delete all children of thisMom //var deleteAllKids = DataSource.childList.Where(c => c._momID == thisMom); //foreach (var child in deleteAllKids) //{ // DataSource.childList.Remove(child); //} //// 2. delete contractList that refers to thisMom (by her kids) //DataSource.contractList.RemoveAll(c => c._childID == thisMom); //// 3. now we can remove the thisMom //DataSource.motherList.RemoveAt(index); //XML_Source.Mothers.Remove(motherElement); }
public bool addSpecilization(Specialization spec) { if (ElementIfExists(XML_Source.specializationRoot, spec.ID) != null) { throw new Exception(spec.ID + " already exists in file"); } XML_Source.specializationRoot.Add(createSpecXElement(spec)); XML_Source.SaveXML <Specialization>(); nextSpecID++; return(true); }
bool removeElementFromXML(XElement XRoot, uint ID) { XElement foundElement = ElementIfExists(XRoot, ID); if (foundElement != null) // element found { foundElement.Remove(); XML_Source.SaveXML <Specialization>(); return(true); } else { throw new Exception("element " + ID + " not found in XML"); } }
public void changePass(string code) { if (code.Length < 4) { throw new Exception("Password must be minimum 4 characters!"); } var deletecode = (from n in XML_Source.Passwords.Elements() select n).First(); deletecode.Remove(); // clears the password existing XML_Source.SavePasswords(); XML_Source.Passwords.Add(code.toXMLPassword()); XML_Source.SavePasswords(); }
public void deleteNanny(long nanny) //is XML { XElement nannyElement = (from n in XML_Source.Nannys.Elements() where Convert.ToInt64(n.Element("id").Value) == nanny select n).FirstOrDefault(); if (nannyElement != null) { nannyElement.Remove(); XML_Source.SaveNannys(); } else { throw new Exception("the nanny is not in list\n"); } }
public void updateContract(Contract thisContract) // is XML { var index = (from n in XML_Source.Contracts.Elements() where Convert.ToInt64(n.Element("id").Value) == thisContract._contractID select n).FirstOrDefault(); if (index != null) { index.ReplaceWith(thisContract.toXML()); XML_Source.SaveContracts(); } else { throw new Exception("Contract doesn't exist in the system"); } }
public bool addContract(Contract contract, bool autoAssignID = true) { if (ElementIfExists(XML_Source.contractRoot, contract.contractID) != null) { throw new Exception(contract.contractID + " already exists in file"); } if (autoAssignID) { contract.contractID = nextContractID++; } XML_Source.contractRoot.Add(createContractXElement(contract)); XML_Source.SaveXML <Contract>(); return(true); }
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 updateMother(Mother mother) //is XML { XElement motherElement = (from m in XML_Source.Mothers.Elements() where Convert.ToInt32(m.Element("id").Value) == mother._momID select m).FirstOrDefault(); if (motherElement != null) { motherElement.Remove(); XML_Source.Mothers.Add(mother.toXML()); XML_Source.SaveMothers(); } else { throw new Exception("Mother doesn't exist in the system"); } }
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 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(); } }
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); }