Esempio n. 1
0
 /// <summary>
 /// update the numabr of nanny's children
 /// </summary>
 /// <param name="nanny">the nanny that we whant to update her children number</param>
 /// <param name="num">flag, if num = 1 add 1 else sub 1 </param>
 /// <remarks>
 /// accept nanny and a number
 /// if number = 1, add 1 to nanny's children
 /// else reduce nanny's children by 1
 /// if didn't find the nanny throw exception
 /// </remarks>
 public void UpdateNannyChildren(Nanny nanny, int?num)
 {
     try
     {
         XElement nannyElment = FindNannyXml(nanny.ID);
         if (nannyElment != null)
         {
             if (num == 1)
             {
                 // add 1
                 nannyElment.Element("Children").SetValue(nanny.Children + 1);
             }
             else
             {
                 //reduce by 1
                 nannyElment.Element("Children").SetValue(nanny.Children - 1);
             }
             nannyXml.saveFile();
         }
         else
         {
             throw new DALException(nanny.FullName() + " dosn't exsist", "AddNannyChildren");
         }
     }
     catch (Exception)
     {
         throw new DALException("Failed in", "AddNannyChildren");
     }
 }
Esempio n. 2
0
 /// <summary>
 /// update nanny
 /// </summary>
 /// <remarks></remarks>
 /// <param name="nanny">the new Nanny that replace the old nanny</param>
 /// <remarks>
 /// accept nanny, delete the old nanny and replace it with the new nanny
 /// if didn't find the nanny to delete, or can't add the new nanny throw exception
 /// </remarks>
 public void UpdateNanny(Nanny nanny)
 {
     if (FindNanny(nanny))
     {
         DeleteNanny(nanny);
         try
         {
             AddNanny(nanny);
         }
         catch (DALException)
         {
             throw new DALException("can't update " + nanny.FullName() + "details", "update nanny");
         }
     }
     else
     {
         throw new DALException(nanny.FullName() + " dosn't exsist", "update nanny");
     }
 }
Esempio n. 3
0
        /* Nanny functions */

        /// <summary>
        /// add nanny to nanny's DB
        /// </summary>
        /// <param name="nanny">the nanny to add to NannyList</param>
        /// <remarks> if find the nanny on the list -
        /// meeans this nanny already exsist throw exception </remarks>
        public void AddNanny(Nanny nanny)
        {
            if (!FindNanny(nanny))
            {
                NannyList().Add(nanny.Clone());
            }
            else
            {
                throw new DALException(nanny.FullName() + " already exsist", "Add nanny");
            }
        }
Esempio n. 4
0
 /// <summary>
 /// delete nanny from nanny's DB
 /// </summary>
 /// <param name="nanny">the nanny to delete from NannyList</param>
 /// <remarks> accept nanny and send to DeleteNanny(int? id) function nanny's id </remarks>
 public void DeleteNanny(Nanny nanny)
 {
     try
     {
         DeleteNanny(nanny.ID);
     }
     catch (DALException ex)
     {
         throw new DALException(nanny.FullName() + " dosn't exsist", ex.sender);
     }
 }
Esempio n. 5
0
 /// <summary>
 /// add nanny to nanny's DB
 /// </summary>
 /// <param name="nanny">the nanny to add to NannyXml</param>
 /// <remarks> if find the nanny on the list -
 /// meeans this nanny already exsist throw exception </remarks>
 public void AddNanny(Nanny nanny)
 {
     if (!FindNanny(nanny))
     {
         nannyXml.LoadData();
         nannyXml.Root.Add(createNanny(nanny));
         nannyXml.saveFile();
     }
     else
     {
         throw new DALException(nanny.FullName() + " already exsist", "Add nanny");
     }
 }
Esempio n. 6
0
        /// <summary>
        /// add contract to contract's DB
        /// </summary>
        /// <param name="contract">the contract to add to ContractList</param>
        /// <remarks>
        /// accept contract, give the contract a number and add to contract list
        /// check that - nanny, mother and child exsist
        /// check also that there this contract dosn't already exsist
        /// throw exceptions accordingly
        /// </remarks>
        public void AddContract(Contract contract)
        {
            contractXml.LoadData();
            configXml.LoadData();
            int    ContractNumber = int.Parse(configXml.Root.Element("ContractNumber").Value);
            Nanny  nanny          = FindNanny(contract.NannyID);
            Mother mother         = FindMother(contract.MotherID);
            Child  child          = FindChild(contract.ChildID);

            if (nanny != null)
            {
                if (mother != null)
                {
                    if (child != null)
                    {
                        if (FindContract(contract.ContractNumber) == null)
                        {
                            // if the contract number equals 0, give a new contract number
                            // if contract number is not 0 - means this is an update contract,
                            // don't give a new contract number
                            if (contract.ContractNumber == null)
                            {
                                contract.ContractNumber = ContractNumber++;
                                configXml.Root.Element("ContractNumber").SetValue(ContractNumber);
                                configXml.saveFile();
                            }
                            contract.IsContractSigned = true;
                            contractXml.Root.Add(createContract(contract));
                            contractXml.saveFile();
                        }
                        else
                        {
                            throw new DALException(child.FirstName + " dosn't exsist", "Add contract");
                        }
                    }
                    else
                    {
                        throw new DALException("this contract number already exsist", "Add contract");
                    }
                }
                else
                {
                    throw new DALException(mother.FullName() + " dosn't exsist", "Add contract");
                }
            }
            else
            {
                throw new DALException(nanny.FullName() + " dosn't exsist", "Add contract");
            }
        }
Esempio n. 7
0
        /* contract functions */

        /// <summary>
        /// add contract to contract's DB
        /// </summary>
        /// <param name="contract">the contract to add to ContractList</param>
        /// <remarks>
        /// accept contract, give the contract a number and add to contract list
        /// check that - nanny, mother and child exsist
        /// check also that there this contract dosn't already exsist
        /// throw exceptions accordingly
        /// </remarks>
        public void AddContract(Contract contract)
        {
            Nanny  nanny  = FindNanny(contract.NannyID);
            Mother mother = FindMother(contract.MotherID);
            Child  child  = FindChild(contract.ChildID);

            if (nanny != null)
            {
                if (mother != null)
                {
                    if (child != null)
                    {
                        if (FindContract(contract.ContractNumber) == null)
                        {
                            // if the contract number equals 0, give a new contract number
                            // if contract number is not 0 - means this is an update contract,
                            // don't give a new contract number
                            if (contract.ContractNumber == null)
                            {
                                contract.ContractNumber = ContractNumber++;
                            }
                            contract.IsContractSigned = true;
                            ContractList().Add(contract.Clone());
                        }
                        else
                        {
                            throw new DALException(child.FirstName + " dosn't exsist", "Add contract");
                        }
                    }
                    else
                    {
                        throw new DALException("this contract number already exsist", "Add contract");
                    }
                }
                else
                {
                    throw new DALException(mother.FullName() + " dosn't exsist", "Add contract");
                }
            }
            else
            {
                throw new DALException(nanny.FullName() + " dosn't exsist", "Add contract");
            }
        }
Esempio n. 8
0
 /// <summary>
 /// update the numabr of nanny's children
 /// </summary>
 /// <param name="nanny">the nanny that we whnt to update her children number</param>
 /// <param name="num">flag, if num = 1 add 1 else sub 1 </param>
 /// <remarks>
 /// accept nanny and a number
 /// if number = 1, add 1 to nanny's children
 /// else reduce nanny's children by 1
 /// if didn't find the nanny throw exception
 /// </remarks>
 public void UpdateNannyChildren(Nanny nanny, int?num)
 {
     if (FindNanny(nanny))
     {
         if (num == 1)
         {
             // add 1
             NannyList().Find(nan => nan.Equals(nanny)).Children++;
         }
         else
         {
             //reduce by 1
             NannyList().Find(nan => nan.Equals(nanny)).Children--;
         }
     }
     else
     {
         throw new DALException(nanny.FullName() + " dosn't exsist", "AddNannyChildren");
     }
 }
Esempio n. 9
0
        /* Nanny functions */

        /// <summary>
        /// add Nanny to nanny's DB
        /// </summary>
        /// <param name="nanny">the nanny to add to NannyList</param>
        /// <remarks>
        /// if nany age is under 18 throw exception
        /// cal dal.addNanny
        /// </remarks>
        public void AddNanny(Nanny nanny)
        {
            if (nanny.NannyAge < 18 || nanny.NannyAge == null)
            {
                throw new BLException(nanny.FullName() + " age is under 18", "add nanny");
            }
            try
            {
                Valid(nanny);
            }
            catch (BLException)
            {
                throw;
            }
            try
            {
                dal.AddNanny(nanny.Clone());
            }
            catch (DALException ex)
            {
                throw new BLException(ex.Message, ex.sender);
            }
        }
Esempio n. 10
0
        /* contract functions */

        /// <summary>
        /// add contract to contract's DB
        /// </summary>
        /// <param name="contract">the contract to add to ContractList</param>
        /// <remarks>
        /// accept contract, update number of nanny's children, that the child has nanny,
        /// the final payment and cal dal.AddContract to add the contract
        /// check that - nanny, mother and child exsist
        /// check also that there this contract dosn't already exsist
        /// throw exceptions accordingly
        /// </remarks>
        public void AddContract(Contract contract)
        {
            Mother mother = FindMother(contract.MotherID);
            Nanny  nanny  = FindNanny(contract.NannyID);
            Child  child  = FindChild(contract.ChildID);

            if (mother == null)
            {
                throw new BLException("mother with ID: " + contract.MotherID + " dosn't exsist", "add contract");
            }
            if (nanny == null)
            {
                throw new BLException("nanny with ID: " + contract.NannyID + " dosn't exsist", "add contract");
            }
            if (child == null)
            {
                throw new BLException("child with ID: " + contract.ChildID + " dosn't exsist", "add contract");
            }
            // if child age is under 3 month throw exception
            if (child.AgeInMonth < 3)
            {
                throw new BLException(child.FirstName + " is under 3 month", "add contrsct");
            }
            if (IsChildInNannyAge(nanny, child.ID) == false)
            {
                throw new BLException(child.FirstName + " is not on nanny's age range", "add contrsct");
            }
            if (child.HaveNanny == true)
            {
                throw new BLException(child.FirstName + " already has a nanny ", "add contrsct");
            }
            // if nanny has more then his max childre throw exception
            if (nanny.Children >= nanny.MaxChildren)
            {
                throw new BLException(nanny.FullName() + " already has " + nanny.MaxChildren + " children", "Add contract");
            }
            try
            {
                // calculate the final payment
                CalculatePayment(contract);
                // update number of nanny's children and that the child has nanny
                UpdateNannyChildren(nanny, 1);
                UpdateHaveNanny(child, true);
                dal.AddContract(contract.Clone());
            }
            catch (BLException ex)
            {
                // if fail at UpdateHaveNanny need to reduce back nanny children
                if (ex.sender == "Update Have Nanny")
                {
                    UpdateNannyChildren(nanny, -1);
                }
                throw;
            }
            catch (DALException ex)
            {
                // if fail at UpdateHaveNanny need to reduce back nanny children,
                // and if fail at AddContract need to reduce back nanny children
                // and change back the have nanny feild of child.
                if (ex.sender == "Update Have Nanny")
                {
                    UpdateNannyChildren(nanny, -1);
                }
                if (ex.sender == "Add contract")
                {
                    UpdateNannyChildren(nanny, -1);
                }
                UpdateHaveNanny(child, false);
                throw new BLException(ex.Message, ex.sender);
            }
        }