示例#1
0
        /// <summary>
        /// addding contract cheacking if contract is properly
        /// </summary>
        public void AddContract(Contract contract)
        {
            int   ChildId = contract.ChildId;
            Child child   = dal.GetChild(ChildId);

            if (child == null)
            {
                //   return false;
                throw new Exception("child with this id no exists...");
            }
            DateTime today = DateTime.Today;
            //           int Age = today.Month - child.ChildDate.Month;
            int Age = today.Year - child.ChildDate.Year;

            if (Age < 3)
            {
                throw new Exception("This child is too young");
            }

            bool haveTime = Isfree(contract);

            if (haveTime)
            {
                contract.ContractFinelSalary = MoneyCalculation(contract);
                dal.AddContract(contract);
            }
            else
            {
                throw new Exception("to nuch children");
            }
        }
示例#2
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);
        }
示例#3
0
        public void AddContract(Contract c)
        {
            bool erId = GetAllEmployer().Any(er => er.Id == c.EmployerId);

            if (erId == false)
            {
                throw new Exception("The employer is not in the list");
            }
            bool eeId = GetAllEmployee().Any(ee => ee.Id == c.EmployeeId);

            if (eeId == false)
            {
                throw new Exception("The employee is not in the list");
            }

            foreach (var item in GetAllEmployer())
            {
                if (item.Id == c.EmployerId)
                {
                    if (item.DateEstablishment > DateTime.Now.AddYears(-1))
                    {
                        throw new Exception("Unable to sign a contract with a new friend who is less than a year");
                    }
                }
            }



            int countEe = 1;

            foreach (var item in GetAllContract())
            {
                if (c.EmployeeId == item.EmployeeId)
                {
                    countEe++;
                }
            }
            int countEr = 1;

            foreach (var item in GetAllContract())
            {
                if (c.EmployerId == item.EmployerId)
                {
                    countEr++;
                }
            }

            c.HourSalaryN = (c.HourSalaryG) * (100 - amla(countEe, countEr)) / 100;

            if (c.DateBegingEmployin >= c.DateEndEmploying)
            {
                throw new Exception("Date Beging must be before Date End");
            }
            if (c.HoursNum > 240)
            {
                throw new Exception("You can work over 240 monthly hours");
            }
            dal.AddContract(c);
        }
示例#4
0
        public void AddContract(BE.Contract contract)
        {
            bool flag;
            int  counter = 0;

            BE.Nanny  nannytemp  = dimp.SearchNany(x => x.NannyId == contract.NannyID).FirstOrDefault();
            BE.Mother mothertemp = dimp.SearchMother(x => x.MomId == contract.MomId).FirstOrDefault();
            BE.Child  childtemp  = dimp.SearchChild(x => x.ChildId == contract.ChildID).FirstOrDefault();
            if (nannytemp == null || mothertemp == null || childtemp == null || (nannytemp.Isspecial == false && childtemp.SpecialBoy == true))
            {
                throw new Exception("וודא שהיקשת ת.ז נכונים עבור אמא ילד ומטפלת!");
            }
            IEnumerable <BE.Contract> tt = dimp.SearchContract(x => x.NannyID == contract.NannyID);

            if (WhatAge(childtemp.ChildBirth) < nannytemp.MinAge || WhatAge(childtemp.ChildBirth) < 0.3 || WhatAge(childtemp.ChildBirth) > nannytemp.MaxAge)
            {
                throw new Exception("canot add this contract! ");
            }

            else
            {
                flag = false;
                for (int i = 0; i < 6; i++)
                {
                    if (nannytemp.Days[i] == false && mothertemp.Days[i] == true)
                    {
                        flag = false;
                    }
                    else//need this day
                    {
                        if (mothertemp.Days[i] == true && nannytemp.Days[i] == true)
                        {
                            if (this.HoursStart(i, mothertemp) > this.HoursStart(i, nannytemp))                                                                                                                                   //שעת התחלה מוקדמת מהרצוי
                            {
                                if ((this.HourEnd(i, mothertemp) < this.HourEnd(i, nannytemp)) || (this.HourEnd(i, mothertemp) == this.HourEnd(i, nannytemp) && this.MinutesEnd(i, mothertemp) <= this.MinutesEnd(i, nannytemp))) //שעת סיום מאוחרת מהרצוי
                                {
                                    flag = true;
                                }
                            }
                            //שעת התחלה שווה לרצוי
                            if (this.HoursStart(i, mothertemp) == this.HoursStart(i, nannytemp) && (this.MinutesStart(i, mothertemp) <= MinutesStart(i, nannytemp)))
                            {
                                if ((this.HourEnd(i, mothertemp) < this.HourEnd(i, nannytemp)) || (this.HourEnd(i, mothertemp) == this.HourEnd(i, nannytemp) && this.MinutesEnd(i, mothertemp) <= this.MinutesEnd(i, nannytemp)))//שעת סיום מאוחרת מהרצוי
                                {
                                    flag = true;
                                }
                            }
                        }
                    }
                    if (flag == false)
                    {
                        i = 6;
                    }
                }
            }
            if (flag == true)
            {
                double          netopay;
                List <BE.Child> listchild  = dimp.MomChildAtNany(contract.MomId, contract.NannyID);
                int             numofchild = listchild.Count;
                if (nannytemp.IsHours)
                {
                    for (int i = 0; i < 6; i++)
                    {
                        if (mothertemp.Days[i])
                        {
                            int minstart  = MinutesStart(i, mothertemp);
                            int hourstart = this.HoursStart(i, mothertemp);
                            int timestart = hourstart * 60 + minstart;
                            int minend    = this.MinutesEnd(i, mothertemp);
                            int hourend   = this.HourEnd(i, mothertemp);
                            int timeend   = hourstart * 60 + minstart;

                            counter += timeend - timestart;
                        }
                    }
                    netopay = nannytemp.MoneyForHour * 0.16666667 * counter * 4;
                }
                else
                {
                    netopay = nannytemp.MoneyForMonth;
                }
                for (int i = 0; i < numofchild; i++)
                {
                    netopay *= 0.8;
                }
                contract.PayForMonth = netopay;
                dimp.AddContract(contract);
            }
        }