public async Task <PlaceBetFailure?> PlaceBet(TUser user, Side side, long amount) { if (amount < _minBet) { return(new PlaceBetFailure.BetTooLow(_minBet)); } if (amount > _maxBet) { return(new PlaceBetFailure.BetTooHigh(_maxBet)); } foreach ((Side loopSide, Dictionary <TUser, long> betsForSide) in _bets) { if (Equals(loopSide, side)) { long existingBet = betsForSide.GetValueOrDefault(user, 0); if (existingBet > amount) { return(new PlaceBetFailure.CannotLowerBet(existingBet)); } } else { if (betsForSide.ContainsKey(user)) { return(new PlaceBetFailure.CannotChangeSide(loopSide)); } } } long currentBet = _bets[side].GetValueOrDefault(user, 0); long availableForBet = await _getAvailableMoney(user) + currentBet; if (amount > availableForBet) { return(new PlaceBetFailure.InsufficientFunds(availableForBet)); } _bets[side][user] = amount; BetPlaced?.Invoke(this, new BetPlacedEventArgs <TUser>(user, side, amount)); return(null); }
protected virtual void OnBetPlaced(EventArgs e) { BetPlaced?.Invoke(this, e); }