public async Task <int> CreateAsync(CreateTransaction model) { if (!model.FromAccountId.HasValue && !model.ToAccountId.HasValue) { throw new ArgumentException("AccountId is missing."); } if (model.FromAccountId.HasValue && !(await _accountsRepository.ExistsAsync(model.FromAccountId.Value, model.UserId))) { throw new ArgumentException("FromAccount doesn't belong to user with specified userId."); } if (model.ToAccountId.HasValue && !(await _accountsRepository.ExistsAsync(model.ToAccountId.Value, model.UserId))) { throw new ArgumentException("ToAccount doesn't belong to user with specified userId."); } var transaction = _mapper.Map <Transaction>(model); return(await _transactionsRepository.CreateAsync(transaction)); }