/// <summary> /// add Contract to the Data Source /// </summary> /// <param name="myContract"></param> public void AddContract(Contract myContract) { if (FindContract(myContract.TransactionNumber) != null) { throw new Exception("Contract already exist"); } Nanny nan = FindNanny(myContract.NannyId); if (nan == null) // nanny not found { throw new Exception("nanny of this contract not exist"); } Child chi = FindChild(myContract.ChildId); Mother mom = FindMother(chi.MotherId); if (mom == null) // mother not found { throw new Exception("mother of this contract not exist"); } if ((DateTime.Now.Year - chi.DateOfBirth.Year) > nan.MaxChildAge) { throw new Exception("child age exceeded from the max age!"); } if ((DateTime.Now.Year - chi.DateOfBirth.Year) < nan.MinChildAge) { throw new Exception("child age exceeded from the min age!"); } myContract.ContractSigned = true; nan.NumOfContract += 1; myXML.UpdateNanny(nan); myContract.TransactionNumber = NextTransactionNumber++; myXML.UpdateTransactionNumber(NextTransactionNumber); myXML.AddContract(myContract); }