public async Task <Domain.Entities.Transaction> Withdraw(decimal amount) { ValidationTransaction.ValidateAmount(amount); var user = await _userService.FindFirstAsync(u => u.Id == _userId); ValidationTransaction.ValidateAmountBank(amount, user); var withdraw = _transactionService.Withdraw(amount, _userId); user.AmountBank -= amount; user.AmountWallet += amount; _userService.Update(user); await SaveAsync(); return(withdraw); }
public async Task <Domain.Entities.Transaction> Deposit(decimal amount) { ValidationTransaction.ValidateAmount(amount); var user = await _userService.FindFirstAsync(u => u.Id == _userId); ValidationTransaction.ValidateAmountWallet(amount, user); var deposit = _transactionService.Deposit(amount, _userId); user.AmountBank += amount; user.AmountWallet -= amount; _userService.Update(user); await SaveAsync(); return(deposit); }
public async Task <Domain.Entities.Transaction> Transfer(decimal amount, int userIdDestiny) { ValidationTransaction.ValidateAmount(amount); ValidationTransaction.ValidateUserTransfer(_userId, userIdDestiny); var userDestiny = await _userService.FindFirstAsync(u => u.Id == userIdDestiny); ValidationTransaction.ValidatePassport(userDestiny); var user = await _userService.FindFirstAsync(u => u.Id == _userId); ValidationTransaction.ValidateAmountBank(amount, user); var transfer = _transactionService.Transfer(amount, _userId, userIdDestiny); user.AmountBank -= amount; userDestiny.AmountBank += amount; _userService.Update(user); _userService.Update(userDestiny); await SaveAsync(); return(transfer); }