public async Task Handle(IbanAdded notification, CancellationToken cancellationToken) { var expenses = await _expenseService.UpdateExpensesWhen(notification); await Task.WhenAll(expenses.Select(_expenseRepository.UpdateAsync)); await _expenseRepository.SaveChangesAsync(); }
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); }