예제 #1
0
        public async Task <List <SavingsTransaction> > CreateSavingsTransactionsWhen(SavingsAccountAdded notification)
        {
            var expenses = await _expenseRepository.FindByIban(notification.Iban);

            var result = expenses
                         .Select(x => _savingsTransactionFactory.CreateFrom(SavingsTransactionType.BankTransfer, x.Value, x.ExpenseDate, x.Details1, x.Details2, x.ExpenseSourceId))
                         .ToList();

            return(result);
        }
예제 #2
0
        public async Task Handle(SavingsAccountAdded notification, CancellationToken cancellationToken)
        {
            var savings = await _savingsService.CreateSavingsTransactionsWhen(notification);

            await Task.WhenAll(savings.Select(_savingsTransactionRepository.AddAsync));

            await _savingsTransactionRepository.SaveChangesAsync();

            var expenses = await _expenseRepository.FindByIban(notification.Iban);

            await Task.WhenAll(expenses.Select(x =>
            {
                x.Delete();
                return(_expenseRepository.UpdateAsync(x));
            }));

            await _expenseRepository.SaveChangesAsync();
        }
예제 #3
0
        public async Task <List <Expense> > UpdateExpensesWhen(IbanAdded notification)
        {
            var expenseRecipient =
                await _expenseRecipientRepository.FindById(notification.ExpenseRecipientId);

            if (expenseRecipient == null)
            {
                return(new List <Expense>());
            }

            var expenses = await _expenseRepository.FindByIban(notification.Iban);

            foreach (var expense in expenses)
            {
                expense.SetExpenseRecipient(expenseRecipient.ExpenseRecipientId);
                expense.SetExpenseCategory(expenseRecipient.ExpenseCategoryId);
            }

            return(expenses);
        }