Пример #1
0
        /// <summary>
        /// Reverses the processing of a Splitwise transaction. Meaning that the Splitwise account balances are updated
        /// if needed.
        /// </summary>
        /// <param name="transaction">The Splitwise transaction.</param>
        private void Revert(SplitwiseTransactionEntity transaction)
        {
            transaction.VerifyProcessable();

            var splitwiseAccount = this.Context.Accounts.GetSplitwiseEntity();

            var(historicalEntriesToEdit, _) =
                this.GetBalanceEntriesToEdit(splitwiseAccount.Id, transaction.Date);

            var mutationAmount = transaction.GetSplitwiseAccountDifference();

            foreach (var entry in historicalEntriesToEdit)
            {
                entry.Balance -= mutationAmount;
            }
        }
Пример #2
0
        /// <summary>
        /// Processes a Splitwise transaction. Meaning that the Splitwise account balances are updated if needed.
        /// </summary>
        /// <param name="transaction">The Splitwise transaction.</param>
        /// <param name="addedDailyBalances">The daily balances that were already added. This is needed since the
        /// context does not contain already added entities, resulting in possible double daily balances which results
        /// in an error.</param>
        private void Process(
            SplitwiseTransactionEntity transaction, List <DailyBalanceEntity> addedDailyBalances, TransactionType type)
        {
            transaction.VerifyProcessable();

            var splitwiseAccount = this.Context.Accounts.GetSplitwiseEntity();

            var(historicalEntriesToEdit, newHistoricalEntry) =
                this.GetBalanceEntriesToEdit(splitwiseAccount.Id, transaction.Date, addedDailyBalances);
            if (newHistoricalEntry.IsSome)
            {
                addedDailyBalances.Add(newHistoricalEntry.Value);
            }
            var mutationAmount = transaction.GetSplitwiseAccountDifference();

            foreach (var entry in historicalEntriesToEdit)
            {
                entry.Balance += mutationAmount;
            }
        }