Ejemplo n.º 1
0
        /// <summary>
        /// add new contract.
        /// conditions:
        /// 1: the child is above 3 month old
        /// 2: the nanny not reached her max amount of children
        /// </summary>
        /// <param name="myContract"></param>
        public void AddContract(Contract myContract)
        {
            Child  ch  = myIdal.FindChild(myContract.ChildId);
            Nanny  nan = myIdal.FindNanny(myContract.NannyId);
            Mother mom = myIdal.FindMother(ch.MotherId);

            DateTime ourTime = DateTime.Now.AddMonths(-3);

            if (ch.DateOfBirth > ourTime)
            {
                throw new Exception("Child under 3 month");
            }

            if (nan.MaxChildNumber == nan.NumOfContract)
            {
                throw new Exception("nanny already reach the max amount of children ");
            }

            int newSalary = CalculateSalary(ch, nan, mom, myContract.ConType); // gets the new salary

            if (myContract.ConType == ContractType.hourly)                     // if the contract required hourly wage
            {
                myContract.HourlyWage = newSalary;
            }
            else
            {
                myContract.MonthlyWage = newSalary;
            }

            myIdal.AddContract(myContract);

            nan.NumOfContract += 1;;  // updating the number of contracts
            myIdal.UpdateNanny(nan);
        }