public async Task <IActionResult> Withdraw( Guid userId, [FromBody][Required] WalletWithdrawDto wallet) { await _walletService.Withdraw(userId, wallet); return(NoContent()); }
public async Task Withdraw(Guid userId, WalletWithdrawDto walletDto) { await CheckUserExists(userId); Wallet wallet = await CreateWalletIfNotExist(userId, walletDto.Currency); if (!TrySubstractAmount(wallet.Total, walletDto.Amount, out decimal newTotal, out string error)) { throw new InvalidRequestException(error); } wallet.Total = newTotal; await _db.SaveChangesAsync(); }