public async Task Handler(WithdrawCommand command) { var account = _context.Accounts.SingleOrDefault(x => x.AccountId == command.AccountId); account.Balance -= command.Amount; var transaction = new CreateTransactionCommand() { Operation = "Withdraw in cash", Account = account, Amount = command.Amount }; var handler = new CreateTransactionHandler(transaction); await _context.SaveChangesAsync(); }
public async Task Handler(CreateTransactionCommand command) { var transaction = new Transaction() { AccountId = command.Account.AccountId, Date = DateTime.Now, Type = "Credit", Amount = command.Amount, Balance = command.Account.Balance + command.Amount, Bank = "CT" }; if (command.Operation != null || command.Operation != "") { transaction.Operation = command.Operation; } await _context.Transactions.AddAsync(transaction); await _context.SaveChangesAsync(); }
public CreateTransactionHandler(CreateTransactionCommand command) { _context = new BankContext(); Handler(command); }