public async Task AddTransactionAsync(AddTransaction command) { var results = addTransactionValidator.Validate(command); if (!results.IsValid) { throw new ArgumentException(results.ToString("~")); } var user = await userRepository.GetFirstUserAsync(); if (command.Type == ExtendedTransactionType.Transfer) { if (command.Amount > 0) { command.Amount *= (-1); } if (command.TransferAmount < 0) { command.TransferAmount *= (-1); } var transactionExpense = Transaction.Create(command.AccountId, TransactionType.Expense, command.Amount, command.Date, command.Name, command.Comment, user.Id, false, command.CategoryId, command.ExternalId, command.Latitude, command.Longitude); await transactionRepository.AddTransactionAsync(transactionExpense); var transactionIncome = Transaction.Create(command.TransferAccountId.Value, TransactionType.Income, command.TransferAmount, command.TransferDate, command.Name, command.Comment, user.Id, false, command.CategoryId, command.TransferExternalId, command.Latitude, command.Longitude); await transactionRepository.AddTransactionAsync(transactionIncome); var transfer = Transfer.Create(transactionExpense.Id, transactionIncome.Id, command.Rate); await transactionRepository.AddTransferAsync(transfer); await this.CreateTagsToTransaction(command.Tags, transactionExpense.Id); await this.MergeFiles(command.FileGuid, transactionExpense); } else { var type = command.Type.ToTransactionType(); if (type == TransactionType.Expense && command.Amount > 0) { command.Amount *= (-1); } else if (type == TransactionType.Income && command.Amount < 0) { command.Amount *= (-1); } var transaction = Transaction.Create(command.AccountId, type, command.Amount, command.Date, command.Name, command.Comment, user.Id, false, command.CategoryId, command.ExternalId, command.Latitude, command.Longitude); await this.transactionRepository.AddTransactionAsync(transaction); await this.CreateTagsToTransaction(command.Tags, transaction.Id); await this.MergeFiles(command.FileGuid, transaction); } }