コード例 #1
0
ファイル: PaymentManager.cs プロジェクト: schulz3000/MoneyFox
        /// <summary>
        ///     Deletes all the payments and the recurring payments associated with the account.
        /// </summary>
        /// <param name="accountViewModel">The associated Account.</param>
        public void DeleteAssociatedPaymentsFromDatabase(AccountViewModel accountViewModel)
        {
            var paymentToDelete = paymentRepository
                                  .GetList(x => (x.ChargedAccountId == accountViewModel.Id) || (x.TargetAccountId == accountViewModel.Id))
                                  .OrderByDescending(x => x.Date)
                                  .ToList();

            foreach (var payment in paymentToDelete)
            {
                if (payment.IsRecurring)
                {
                    foreach (var recTrans in recurringPaymentRepository.GetList(x => x.Id == payment.RecurringPaymentId)
                             )
                    {
                        recurringPaymentRepository.Delete(recTrans);
                    }
                }

                paymentRepository.Delete(payment);
            }
        }
コード例 #2
0
        public bool DeletePayment(Payment payment)
        {
            paymentRepository.Delete(payment);

            // If this payment was the last one for the linked recurring payment
            // delete the db entry for the recurring payment.
            var succeed = true;

            if (paymentRepository.GetList().All(x => x.RecurringPaymentId != payment.RecurringPaymentId))
            {
                var recurringList = recurringPaymentRepository
                                    .GetList(x => x.Id == payment.RecurringPaymentId)
                                    .ToList();

                foreach (var recTrans in recurringList)
                {
                    if (!recurringPaymentRepository.Delete(recTrans))
                    {
                        succeed = false;
                    }
                }
            }
            return(succeed);
        }