Esempio n. 1
0
        private void AddMonkeyBet(Game res)
        {
            var monkeyUserName = WebConfigurationManager.AppSettings["MonkeyUserName"];

            if (!String.IsNullOrEmpty(monkeyUserName))
            {
                var monkeyUser = usersRepository.GetUser(monkeyUserName);
                if (monkeyUser == null)
                {
                    Trace.TraceError("Monkey user {0} was not found, will not add monkey bet", monkeyUserName);
                }
                var randomResults = new RandomResults();
                var result        = randomResults.GetRandomResult();
                betsRepository.InsertBet(new Bet()
                {
                    GameId      = res.GameId,
                    UserId      = monkeyUser.Id,
                    HomeScore   = result.Key,
                    AwayScore   = result.Value,
                    CardsMark   = randomResults.GetRandomMark(),
                    CornersMark = randomResults.GetRandomMark()
                });
                betsRepository.Save();
            }
        }
        private void SetupGames(MundialitoContext context, ITournamentCreator tournamentCreator)
        {
            var games = tournamentCreator.GetGames(stadiumsDic, teamsDic);

            games.ForEach(stadium => context.Games.Add(stadium));

            context.SaveChanges();

            if (monkeyEnabled)
            {
                var monkey = userManager.FindByName(WebConfigurationManager.AppSettings["MonkeyUserName"]);

                var randomResults = new RandomResults();

                context.Games.ToList().ForEach(game =>
                {
                    var result         = randomResults.GetRandomResult();
                    var newBet         = new Bet();
                    newBet.UserId      = monkey.Id;
                    newBet.GameId      = game.GameId;
                    newBet.HomeScore   = result.Key;
                    newBet.AwayScore   = result.Value;
                    newBet.CardsMark   = randomResults.GetRandomMark();
                    newBet.CornersMark = randomResults.GetRandomMark();
                    context.Bets.Add(newBet);
                });

                context.SaveChanges();
            }
        }
        private void SetupGames(MundialitoContext context, ITournamentCreator tournamentCreator)
        {
            var games = tournamentCreator.GetGames(stadiumsDic, teamsDic);

            games.ForEach(stadium => context.Games.Add(stadium));

            context.SaveChanges();

            if (monkeyEnabled)
            {
                var monkey = userManager.FindByName(WebConfigurationManager.AppSettings["MonkeyUserName"]);

                var randomResults = new RandomResults();

                context.Games.ToList().ForEach(game =>
                {
                    var result         = randomResults.GetRandomResult();
                    var newBet         = new Bet();
                    newBet.UserId      = monkey.Id;
                    newBet.GameId      = game.GameId;
                    newBet.HomeScore   = result.Key;
                    newBet.AwayScore   = result.Value;
                    newBet.CardsMark   = randomResults.GetRandomMark();
                    newBet.CornersMark = randomResults.GetRandomMark();
                    context.Bets.Add(newBet);
                });

                Random rnd    = new Random();
                var    index  = rnd.Next(0, teamsDic.Count);
                int    teamId = teamsDic.Values.ElementAt(index).TeamId;
                index = rnd.Next(0, playersDic.Count);
                int playerId = playersDic.Values.ElementAt(index).PlayerId;

                context.GeneralBets.Add(new GeneralBet
                {
                    GoldBootPlayerId = playerId,
                    WinningTeamId    = teamId,
                    User             = monkey
                });

                context.SaveChanges();
            }
        }