public Task Deposit(Operation operation) { if (operation.Amount <= 0) { throw new InvalidValueException(nameof(operation.Amount)); } _account.State.Balance += operation.Amount; var operationHistory = new OperationHistoryEntry { Date = _time.Now, Amount = operation.Amount, Description = "Deposit", Tags = operation.Tags }; _account.State.History.Add(operationHistory); return(_account.WriteStateAsync()); }
public Task Withdraw(Operation operation) { if (operation.Amount <= 0) { throw new InvalidValueException(nameof(operation.Amount)); } if (_account.State.Balance < operation.Amount) { throw new InsufficientBalanceException(); } _account.State.Balance -= operation.Amount; var operationHistory = new OperationHistoryEntry { Date = _time.Now, Amount = -(operation.Amount), Description = "Withdraw", Tags = operation.Tags }; _account.State.History.Add(operationHistory); return(_account.WriteStateAsync()); }