public async Task Handle(DirectDebitAdded 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(DirectDebitAdded notification) { var expenseRecipient = await _expenseRecipientRepository.FindById(notification.ExpenseRecipientId); if (expenseRecipient == null) { return(new List <Expense>()); } var expenses = await _expenseRepository.FindByDirectDebitCode(notification.Code); foreach (var expense in expenses) { expense.SetExpenseRecipient(expenseRecipient.ExpenseRecipientId); expense.SetExpenseCategory(expenseRecipient.ExpenseCategoryId); } return(expenses); }