Пример #1
0
        /// <summary>
        /// returns the salary for the nanny considering the amount of the child's brothers that the nanny already treat.
        /// </summary>
        /// <param name="myChild"></param>
        /// <param name="myNanny"></param>
        /// <param name="myMother"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public int CalculateSalary(Child myChild, Nanny myNanny, Mother myMother, ContractType type)
        {
            IEnumerable <Child> brothers = myIdal.GetAllChildsByMother(myMother);                //all the sons of this mom

            brothers = brothers.Where(x => x.Id != myChild.Id);                                  // the brothers without this child
            IEnumerable <Contract> conts = myIdal.GetAllContracts(x => x.NannyId == myNanny.Id); //all the contract of this nanny
            int amount = conts.Count(x => brothers.Any(y => y.Id == x.ChildId));                 // counting the brothers
            int salary;

            if (type == ContractType.hourly) // the nanny get hourly wage
            {
                salary = NannyWorkHours(myNanny) * 4 * myNanny.HourlyWage;
                while (amount > 0)
                {
                    salary = (int)(salary * 0.98); // 2% per brother
                    amount--;
                }

                return(salary);
            }

            // not per hour salary
            salary = myNanny.MonthlyWage;
            while (amount > 0)
            {
                salary = (int)(salary * 0.98); // 2% per brother
                amount--;
            }
            return(salary);
        }