Esempio n. 1
0
        public Invoice InitializeInvoice(BabySitterContract babySitterContract)
        {
            Invoice invoice = new Invoice()
            {
                totalPayment = decimal.Zero,
                response     = validation.ValidateUserInput(babySitterContract)
            };

            return(invoice);
        }
        public bool ValidateUserInput(BabySitterContract babySitterContract)
        {
            bool validateEndTime   = BabysitterEndTimeIsFourAmOrEarlier(babySitterContract.BabysitterEndTime);
            bool validateStartTime = BabysitterStartTimeIsFivePmOrLater(babySitterContract.BabysitterStartTime);
            bool startAndEndAreInChronologicalOrder     = BabysitterStartTimeIsBeforeBabysitterEndTime(babySitterContract.BabysitterStartTime, babySitterContract.BabysitterEndTime);
            bool allRateStartTimesAreBeforeRateEndTimes = AllRateStartTimesAreBeforeRateEndTimes(babySitterContract);

            return(validateEndTime && validateStartTime &&
                   startAndEndAreInChronologicalOrder &&
                   allRateStartTimesAreBeforeRateEndTimes);
        }
Esempio n. 3
0
        public Invoice CalculateBabysitterPaymentFromBabySitterContract(BabySitterContract babySitterContract)
        {
            var invoice = InitializeInvoice(babySitterContract);

            //if validation fails, return the invoice and do not calculate total payment
            if (!invoice.response)
            {
                return(invoice);
            }

            CalculateTotalBabysitterPayment(babySitterContract, invoice);

            return(invoice);
        }
        public bool AllRateStartTimesAreBeforeRateEndTimes(BabySitterContract babySitterContract)
        {
            bool result = true;

            foreach (Rate rate in babySitterContract.Rates)
            {
                if (rate.rateEndTime <= rate.rateStartTime)
                {
                    result = false;
                    break;
                }
            }
            return(result);
        }
Esempio n. 5
0
        public void CalculateTotalBabysitterPayment(BabySitterContract babySitterContract, Invoice invoice)
        {
            bool stillWorking = false;

            foreach (Rate rate in babySitterContract.Rates)
            {
                // Set up variables
                decimal hoursWorkedAtCurrentRate;
                decimal ratePayment = decimal.Zero;

                bool babySitterStartTimeisInRateBlock = DetermineIfBabysitterStartTimeIsInRateBlock(babySitterContract, rate);
                bool babySitterEndTimeisInRateBlock   = DetermineIfBabysitterEndTimeIsInRateBlock(babySitterContract, rate);

                //if the start and end time are both in a single rate block, update payment and return the invoice
                if (babySitterStartTimeisInRateBlock && babySitterEndTimeisInRateBlock)
                {
                    invoice.totalPayment = CalculatePaymentIfBabysitterWorksDuringOnlyOneRate(invoice, babySitterContract, rate);
                    return;
                }

                // otherwise, if the time the babysitter is there spans across multiple rates
                if (babySitterStartTimeisInRateBlock)
                {
                    hoursWorkedAtCurrentRate = rate.rateEndTime - babySitterContract.BabysitterStartTime;
                    ratePayment  = hoursWorkedAtCurrentRate * rate.dollarsPerHour;
                    stillWorking = true;
                }

                else if (babySitterEndTimeisInRateBlock)
                {
                    hoursWorkedAtCurrentRate = babySitterContract.BabysitterEndTime - rate.rateStartTime;
                    ratePayment  = hoursWorkedAtCurrentRate * rate.dollarsPerHour;
                    stillWorking = false;
                }

                //otherwise if stillWorking is true, babysitterEndTime hasn't been reached &
                //we can assume they're working the whole time during the rate block
                else if (stillWorking)
                {
                    hoursWorkedAtCurrentRate = rate.rateEndTime - rate.rateStartTime;
                    ratePayment = hoursWorkedAtCurrentRate * rate.dollarsPerHour;
                }
                invoice.totalPayment += ratePayment;
            }
        }
Esempio n. 6
0
 public decimal CalculatePaymentIfBabysitterWorksDuringOnlyOneRate(Invoice invoice, BabySitterContract babySitterContract, Rate rate)
 {
     invoice.totalPayment = rate.dollarsPerHour *
                            (babySitterContract.BabysitterEndTime - babySitterContract.BabysitterStartTime);
     return(invoice.totalPayment);
 }
Esempio n. 7
0
 public bool DetermineIfBabysitterEndTimeIsInRateBlock(BabySitterContract babySitterContract, Rate rate)
 {
     return(babySitterContract.BabysitterEndTime > rate.rateStartTime &&
            babySitterContract.BabysitterEndTime <= rate.rateEndTime);
 }