public void Add_Contract(Contract contract1) { //check that this child hasnt existed in this nanny already if (GetAll_Contract(con => con.Nanny_Id == contract1.Nanny_Id && con.Child_Id == contract1.Child_Id).Count() != 0) { throw new Exception("this contract has allready been in system"); } Child ch = Get_Child(contract1.Child_Id); if (ch == null)//cant add contract without child { throw new Exception("child in contract doesnt exist"); } int age_in_days = (DateTime.Now.Subtract(ch.Birth_Date).Days);//we make minus between now and birth date and take all the days that he lives if (age_in_days / 30 < 3) { throw new Exception("cant add to contract,child that is less then 3 monthes"); } Nanny nan = Get_Nanny(contract1.Nanny_Id); if (nan == null)//cant add contract without nanny { throw new Exception("nanny in contract doesnt exist"); } var nanny_contracts = GetAll_Contract(con => con.Nanny_Id == nan.Id);//return all previous contracts of this nanny int sum = 0; foreach (var item in nanny_contracts)//counts all of this nanny's contracts { sum++; } if (sum == nan.Max_Children)//shr took her max { throw new Exception("this nanny cant take more children"); } if (age_in_days / 30 < nan.Min_Kid_Age || age_in_days / 30 > nan.Max_Kid_Age)//if age of child isnt in range of allowed ages for this nan { throw new Exception("this nanny cant take this age of child"); } Calculate_Salary(contract1, nan, ch);//activate func that puts in the correct salary my_dal.Add_Contract(contract1); }