public async Task Handle(Command request, CancellationToken cancellationToken) { int expenseCategoryId; if (request.Category.IsNew) { var expenseCategory = new ExpenseCategory(request.Category.Name); await _expenseCategoryRepository.AddAsync(expenseCategory); await _expenseCategoryRepository.SaveChangesAsync(); expenseCategoryId = expenseCategory.ExpenseCategoryId; } else { expenseCategoryId = request.Category.ExpenseCategoryId.Value; } var expense = await _expenseRepository.FindById(request.ExpenseId); if (!request.JustThisOne && expense.ExpenseRecipientId.HasValue) { var expenseRecipient = await _expenseRecipientRepository.FindById(expense.ExpenseRecipientId.Value); expenseRecipient.ChangeExpenseCategory(expenseCategoryId, expense.ExpenseMonth); await _expenseRecipientRepository.SaveChangesAsync(); } else { expense.SetExpenseCategory(expenseCategoryId); await _expenseRepository.SaveChangesAsync(); } }