public async Task <Transaction> UpdateTransaction(Transaction transaction, Category newCategory, double newAmount, string newComments)
        {
            const string commandText =
                "UPDATE Transactions " +
                "SET Category = (SELECT Id FROM Categories WHERE Name = @category), Amount = @amount, Comments = @comments, LastUpdateTime = @now,LastUpdateAccount = @account " +
                "WHERE Id = @id";

            using (var dbConnection = GetConnection())
            {
                using (var command = new SQLiteCommand(dbConnection)
                {
                    CommandText = commandText
                })
                {
                    command.Parameters.AddWithValue("@id", transaction.Id);
                    command.Parameters.AddWithValue("@category", newCategory.Name);
                    command.Parameters.AddWithValue("@amount", newAmount);
                    command.Parameters.AddWithValue("@comments", newComments);
                    command.Parameters.AddWithValue("@now", DateTime.Now);
                    command.Parameters.AddWithValue("@account", _account);
                    dbConnection.Open();
                    await command.ExecuteNonQueryAsync();
                }
            }
            var updatedTransaction = await GetTransaction(transaction.Id);

            TransactionUpdated?.Invoke(this, new TransactionUpdateEventArgs(transaction, updatedTransaction));

            return(updatedTransaction);
        }
Beispiel #2
0
        // The rebalancing could occur twice.
        private void When(TransactionUpdated e)
        {
            var index = _transactions.FindIndex(t => t.Id == e.Id);

            if (e.Timestamp.HasValue)
            {
                var transaction = _transactions[index];
                _transactions.RemoveAt(index);
                transaction.Timestamp = e.Timestamp.Value;
                int newIndex = _transactions.BinarySearch(transaction);
                _transactions.Insert(~newIndex, transaction);
                Rebalance(Math.Min(index, ~newIndex));
            }
            if (e.Description != null)
            {
                _transactions[index].Description = e.Description;
            }
            if (e.Amount.HasValue)
            {
                decimal previousAmount = _transactions[index].Amount;
                _transactions[index].Amount = e.Amount.Value;
                Rebalance(index);
            }
        }
Beispiel #3
0
 public Task Handle(TransactionUpdated message, IMessageHandlerContext context)
 {
     MarkAsComplete();
     return(Task.CompletedTask);
 }