Пример #1
0
        private (int correctionIndex, double prevEndingBalance) CorrectEarliestTouchedStartingAndEndingBalance(DateTime earliestDayTouched)
        {
            // At first glance, you might wonder: Why do we need to correct the StartingBalance for our first updated/inserted date?
            // After all, a previously existing Date would have had a correct StartingBalance, and we only would have touched
            // the total transaction amount that occurred on that day.
            //
            // The concern is over the scenarios where:
            //      a) We inserted a new entry
            //      b) That entry may be at the start of our overall list of Dates, or it may
            //         be downstream amongst existing dates.
            //
            // In these scenarios, we need to set our StartingBalance for the day.
            //
            double        prevEndingBalance;
            var           correctionIndex           = this._dailyBalances.IndexOfKey(earliestDayTouched);
            IDailyBalance dailyBalanceToBeCorrected = this._dailyBalances.ElementAt(correctionIndex).Value;

            if (correctionIndex == 0)
            {
                // First Date in our system.  We must use the StartingBalance for the BankAccount
                prevEndingBalance = this.StartingBalance;
            }
            else
            {
                // There are dates before us.  Grab the previous date's EndingBalance so that we can correct our
                // StartingBalance appropriately
                prevEndingBalance = this._dailyBalances.ElementAt(correctionIndex - 1).Value.EndingBalance;
            }
            dailyBalanceToBeCorrected.AdjustStartingBalance(prevEndingBalance);
            return(correctionIndex, dailyBalanceToBeCorrected.EndingBalance);
        }
Пример #2
0
 private void CorrectRemainingDaysStartingAndEndingBalances(int correctionIndex, double prevEndingBalance)
 {
     // Correct all days thereafter
     for (correctionIndex += 1;
          correctionIndex < this._dailyBalances.Count;
          correctionIndex += 1)
     {
         IDailyBalance dailyBalanceToBeCorrected = this._dailyBalances.ElementAt(correctionIndex).Value;
         dailyBalanceToBeCorrected.AdjustStartingBalance(prevEndingBalance);
         prevEndingBalance = dailyBalanceToBeCorrected.EndingBalance;
     }
 }