// adds a new contract to the DS public void AddContract(Contract contract) { if (contract.Nanny.NumberOfChildren >= contract.Nanny.MaxChildren) { IncompatibleParametersException E = new IncompatibleParametersException { Message = "This nanny cannot take anymore children" }; throw E; } if (DateTime.Now.Year == contract.Child.BirthDay.Year) { if (DateTime.Now.Month - contract.Child.BirthDay.Month < 3) { AgeException E = new AgeException { Message = "Cannot sign a contract with a child under 3 months." }; throw E; } } if (!GetCompatibleNannysByDistance(contract.Mother) .ToList().Exists(x => x.Id == contract.Nanny.Id) || !GetCompatibleNannys(contract.Mother) .ToList().Exists(x => x.Id == contract.Nanny.Id)) { throw new IncompatibleParametersException { Message = "The nanny is not compatible to the mother." } } ; int brothersWithNanny = GetNumberOfBrothersWithSameNanny (contract.Mother.Id, contract.Nanny.Id); if (contract.Nanny.AllowsSalaryPerHour) { contract.SalaryPerHour = contract.Nanny.SalareyPerHour * (1 - 0.02 * brothersWithNanny); } else { contract.SalaryPerMonth = contract.Nanny.SalareyPerMonth * (1 - 0.02 * brothersWithNanny); } contract.PerMonthOrHour = contract.Nanny.AllowsSalaryPerHour && contract.Mother.WantsSalaryPerHour; DAL.AddContract(contract); }