public void Handle(BetPlaced @event) { EngageWalletChanges( @event.PlayerId, (wallet, _) => wallet.PlaceBet(@event.Amount, @event.RoundId, @event.GameId, @event.GameActionId) ); }
public void Consume(BetPlaced @event) { var paymentRepository = _container.Resolve <IPaymentRepository>(); var playerId = @event.PlayerId; var betAmount = @event.Amount; var offlineDeposits = paymentRepository .OfflineDeposits .Where( x => x.Player.Id == playerId && x.DepositWagering != 0 && x.Status == OfflineDepositStatus.Approved) .OrderBy(x => x.Created) .ToArray(); if (!offlineDeposits.Any()) { return; } var count = 0; while (betAmount != 0 && count < offlineDeposits.Length) { var deposit = offlineDeposits[count]; deposit.DepositWagering = deposit.DepositWagering - betAmount; if (deposit.DepositWagering >= 0) { betAmount = 0; } else { betAmount = -1 * deposit.DepositWagering; } if (deposit.DepositWagering < 0) { deposit.DepositWagering = 0; } count++; } paymentRepository.SaveChanges(); }
public void Handle(BetPlaced placedEvent) { var reportRepository = _reportRepositoryFactory(); var record = reportRepository.PlayerBetHistoryRecords.SingleOrDefault(r => r.GameActionId == placedEvent.GameActionId); if (record != null) { throw new RegoException(string.Format("Player bet history record {0} already exists", placedEvent.RoundId)); } record = reportRepository.PlayerBetHistoryRecords.SingleOrDefault(r => r.RoundId == placedEvent.RoundId); if (record != null) { record.BetAmount += placedEvent.Amount; record.TotalWinLoss -= placedEvent.Amount; reportRepository.SaveChanges(); return; } var brand = _brandQueriesFactory().GetBrandOrNull(placedEvent.BrandId); var player = _playerQueriesFactory().GetPlayer(placedEvent.PlayerId); var game = _gameQueriesFactory().GetGameDtos().SingleOrDefault(g => g.Id == placedEvent.GameId); record = new PlayerBetHistoryRecord { GameActionId = placedEvent.GameActionId, RoundId = placedEvent.RoundId, Brand = brand != null ? brand.Name : null, Licensee = brand != null && brand.Licensee != null ? brand.Licensee.Name : null, Currency = player != null ? player.CurrencyCode : null, GameName = game != null ? game.Name : null, LoginName = player != null ? player.Username : null, UserIP = player != null ? player.IpAddress ?? "127.0.0.1" : null, DateBet = placedEvent.CreatedOn, BetAmount = placedEvent.Amount, TotalWinLoss = -placedEvent.Amount }; reportRepository.PlayerBetHistoryRecords.Add(record); reportRepository.SaveChanges(); }
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); }
public void Apply(BetPlaced @event) { BetsCount++; TotalAmount += @event.Amount; }
protected virtual void OnBetPlaced(EventArgs e) { BetPlaced?.Invoke(this, e); }
public void Consume(BetPlaced message) { _gameSubscriber.Handle(message); }