Ejemplo n.º 1
0
        public void addContract(Contract contract)
        {
            Nanny  n = dal.getNanny(contract.NannyID);
            Child  c = dal.getChild(contract.ChildID);
            Mother m = dal.getMom(c.MotherID);

            if (c.DateOfBirth.Year < 1 && c.DateOfBirth.Month < 3)
            {
                throw new Exception("the child's age is less than 3 month");
            }
            if (n.MaxChilds == (dal.GetAllContract().FindAll(x => x.NannyID == n.ID).Count))
            {
                throw new Exception("this nanny is full");
            }
            if (n.HourlyRate && (contract.HourOrMonth == BE.SalaryBy.Hour))
            {
                int hours = 0;
                for (int i = 0; i < 6; i++)
                {
                    hours += m.HoursOfNeedingNanny[1, i].Hour - m.HoursOfNeedingNanny[0, i].Hour;
                }
                contract.MonthlySalary = n.PricePerHour * 4 * hours;
            }
            else
            {
                contract.MonthlySalary = n.PricePerMonth;
            }

            int momChildren = dal.GetAllContract().FindAll(x => dal.getChild(x.ChildID).MotherID == m.ID && x.NannyID == n.ID).Count;

            for (int i = 0; i < momChildren; i++)
            {
                contract.MonthlySalary = contract.MonthlySalary * 0.02;
            }
            try
            {
                dal.addContract(contract);
            }
            catch (DuplicateWaitObjectException e)
            {
                throw new DuplicateWaitObjectException(e.Message);
            }
        }