Beispiel #1
0
        public ActionResult Game()
        {
            GameViewModel model        = new GameViewModel();
            PokerService  pokerService = new PokerService();
            var           data         = pokerService.GetPokerData();

            model.Users = data.Users;
            return(View(model));
        }
Beispiel #2
0
        public ActionResult Stats()
        {
            ViewBag.Message = "A page to contain stats";

            //grab the data
            List <ScoreboardModel> scoreboard = new List <ScoreboardModel>();

            PokerViewModel          viewModel = _pokerService.GetPokerData();
            List <Data.PokerResult> results   = _pokerService.GetResults();
            List <Data.PokerMatch>  matches   = _pokerService.GetMatches();


            //loop through data and map it to model
            foreach (var user in viewModel.Users)
            {
                int totalIncoming  = 0;
                int totalOutgoings = 0;
                int totalWins      = 0;
                var userResults    = results.Where(x => x.PokerUserId == user.Id).ToList();

                foreach (var result in userResults)
                {
                    var currentMatch = matches.Where(x => x.Id == result.PokerMatchId).FirstOrDefault();
                    var matchResults = results.Where(x => x.PokerMatchId == currentMatch.Id);
                    totalOutgoings += currentMatch.BuyIn;

                    //if this user won
                    if (result.Placing == (int)Enums.Placing.First)
                    {
                        totalWins     += 1;
                        totalIncoming += (currentMatch.BuyIn * matchResults.Count());
                        if (!currentMatch.IsWinnerTakesAll)
                        {
                            //second place gets money back
                            totalIncoming -= currentMatch.BuyIn;
                        }
                    }
                }

                ScoreboardModel userScore = new ScoreboardModel();
                userScore.Name           = user.Name;
                userScore.GamesPlayed    = userResults.Count;
                userScore.TotalWins      = totalWins;
                userScore.TotalIncomings = totalIncoming;
                userScore.TotalOutgoings = totalOutgoings;
                userScore.Profit         = totalIncoming - totalOutgoings;
                userScore.TotalLosses    = userResults.Count - totalWins;
                userScore.WinPercentage  = Math.Round((totalWins * 100.0) / userResults.Count);

                scoreboard.Add(userScore);
            }

            viewModel.Scoreboard = scoreboard;

            return(View(viewModel));
        }