コード例 #1
0
        public void BuildResultsByGameViewModelTest_WhenGameSpreadsExistButNoUserGameSelections_ShouldCreateDefaultUserGameSelections()
        {
            int    currentGameFilterId = 10;
            int    userId = 1;
            string viewBagMessageToUser = string.Empty;
            var    users              = Users;
            var    teams              = Teams;
            var    noBetTeam          = Teams.FirstOrDefault(_ => _.TeamLongName == "No Bet");
            var    noPicksTeam        = Teams.FirstOrDefault(_ => _.TeamLongName == "No Picks");
            var    noWinnerTeam       = Teams.FirstOrDefault(_ => _.TeamLongName == "No Winner");
            var    gameSpreads        = GameSpreads.Where(_ => _.Game.GameFilterId == currentGameFilterId).ToList();
            var    gameResults        = new List <GameResult>();        // if there are no user game selections, no need to worry about results
            var    userGameSelections = new List <UserGameSelection>(); // this is what we are testing...when this is empty
            var    userGameResults    = new List <UserGameResult>();    // if there are no user game selections, then there cannot be any user game results

            // expected
            string expectedMessageToUser = "******";

            ResultsByGameController controller = new ResultsByGameController();
            ResultsByGameViewModel  actual     = controller.BuildResultsByGameViewModel(currentGameFilterId, ref viewBagMessageToUser, users, gameSpreads, gameResults, userGameSelections, userGameResults, noBetTeam, noPicksTeam, noWinnerTeam);

            Assert.AreEqual(expectedMessageToUser, viewBagMessageToUser);

            Assert.AreEqual(14, actual.GameRows.Count);

            AssertResultsByGameGameRows("Indianapolis", "Jacksonville", Convert.ToDecimal(-3.00), "Indianapolis", actual.GameRows[0]);
            AssertResultsByGameGameRows("New England", "Buffalo", Convert.ToDecimal(-11.00), "New England", actual.GameRows[1]);
            AssertResultsByGameGameRows("NY Giants", "Cincinnati", Convert.ToDecimal(-4.00), "Cincinnati", actual.GameRows[2]);
            AssertResultsByGameGameRows("Tampa Bay", "San Diego", Convert.ToDecimal(-3.00), "Tampa Bay", actual.GameRows[3]);
            AssertResultsByGameGameRows("Denver", "Carolina", Convert.ToDecimal(-3.50), "Denver", actual.GameRows[4]);
            AssertResultsByGameGameRows("Miami", "Tennessee", Convert.ToDecimal(-6.00), "Tennessee", actual.GameRows[5]);
            AssertResultsByGameGameRows("Baltimore", "Oakland", Convert.ToDecimal(-7.50), "Baltimore", actual.GameRows[6]);
            AssertResultsByGameGameRows("Atlanta", "New Orleans", Convert.ToDecimal(-2.50), "New Orleans", actual.GameRows[7]);
            AssertResultsByGameGameRows("Detroit", "Minnesota", Convert.ToDecimal(-2.00), "Minnesota", actual.GameRows[8]);
            AssertResultsByGameGameRows("Seattle", "NY Jets", Convert.ToDecimal(-6.50), "Seattle", actual.GameRows[9]);
            AssertResultsByGameGameRows("Dallas", "Philadelphia", Convert.ToDecimal(-1.00), "Dallas", actual.GameRows[10]);
            AssertResultsByGameGameRows("San Francisco", "St. Louis", Convert.ToDecimal(-11.50), "No Winner", actual.GameRows[11]);
            AssertResultsByGameGameRows("Chicago", "Houston", Convert.ToDecimal(-1.00), "Houston", actual.GameRows[12]);
            AssertResultsByGameGameRows("Pittsburgh", "Kansas City", Convert.ToDecimal(-12.50), "Pittsburgh", actual.GameRows[13]);

            int gameRowId = 0;

            Assert.AreEqual(4, actual.GameRows[gameRowId].UsersData.Count);
            AssertResultsByGameGameRowUserData(1, "Favorite", "IND", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[0]);
            AssertResultsByGameGameRowUserData(2, "Favorite", "IND", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[1]);
            AssertResultsByGameGameRowUserData(3, "NoBet", "X", 0, 0, 0, 0, actual.GameRows[gameRowId].UsersData[2]);
            AssertResultsByGameGameRowUserData(4, "Favorite", "IND", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[3]);

            gameRowId = 1;
            Assert.AreEqual(4, actual.GameRows[gameRowId].UsersData.Count);
            AssertResultsByGameGameRowUserData(1, "Favorite", "NE", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[0]);
            AssertResultsByGameGameRowUserData(2, "Favorite", "NE", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[1]);
            AssertResultsByGameGameRowUserData(3, "Favorite", "NE", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[2]);
            AssertResultsByGameGameRowUserData(4, "Favorite", "NE", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[3]);

            gameRowId = 2;
            Assert.AreEqual(4, actual.GameRows[gameRowId].UsersData.Count);
            AssertResultsByGameGameRowUserData(1, "Favorite", "NYG", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[0]);
            AssertResultsByGameGameRowUserData(2, "Favorite", "NYG", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[1]);
            AssertResultsByGameGameRowUserData(3, "Underdog", "CIN", 1, 2, 0, 0, actual.GameRows[gameRowId].UsersData[2]);
            AssertResultsByGameGameRowUserData(4, "Favorite", "NYG", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[3]);

            gameRowId = 3;
            Assert.AreEqual(4, actual.GameRows[gameRowId].UsersData.Count);
            AssertResultsByGameGameRowUserData(1, "Favorite", "TB", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[0]);
            AssertResultsByGameGameRowUserData(2, "Underdog", "SD", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[1]);
            AssertResultsByGameGameRowUserData(3, "Underdog", "SD", 4, -4, 0, 0, actual.GameRows[gameRowId].UsersData[2]);
            AssertResultsByGameGameRowUserData(4, "Favorite", "TB", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[3]);

            gameRowId = 4;
            Assert.AreEqual(4, actual.GameRows[gameRowId].UsersData.Count);
            AssertResultsByGameGameRowUserData(1, "Favorite", "DEN", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[0]);
            AssertResultsByGameGameRowUserData(2, "Favorite", "DEN", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[1]);
            AssertResultsByGameGameRowUserData(3, "Favorite", "DEN", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[2]);
            AssertResultsByGameGameRowUserData(4, "Favorite", "DEN", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[3]);

            gameRowId = 5;
            Assert.AreEqual(4, actual.GameRows[gameRowId].UsersData.Count);
            AssertResultsByGameGameRowUserData(1, "Favorite", "MIA", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[0]);
            AssertResultsByGameGameRowUserData(2, "Favorite", "MIA", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[1]);
            AssertResultsByGameGameRowUserData(3, "Underdog", "TEN", 1, 2, 0, 0, actual.GameRows[gameRowId].UsersData[2]);
            AssertResultsByGameGameRowUserData(4, "Favorite", "MIA", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[3]);

            gameRowId = 6;
            Assert.AreEqual(4, actual.GameRows[gameRowId].UsersData.Count);
            AssertResultsByGameGameRowUserData(1, "Favorite", "BAL", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[0]);
            AssertResultsByGameGameRowUserData(2, "Favorite", "BAL", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[1]);
            AssertResultsByGameGameRowUserData(3, "Favorite", "BAL", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[2]);
            AssertResultsByGameGameRowUserData(4, "Favorite", "BAL", 5, 5, 0, 0, actual.GameRows[gameRowId].UsersData[3]);

            gameRowId = 7;
            Assert.AreEqual(4, actual.GameRows[gameRowId].UsersData.Count);
            AssertResultsByGameGameRowUserData(1, "Favorite", "ATL", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[0]);
            AssertResultsByGameGameRowUserData(2, "Underdog", "NO", 5, 10, 0, 0, actual.GameRows[gameRowId].UsersData[1]);
            AssertResultsByGameGameRowUserData(3, "Underdog", "NO", 1, 2, 0, 0, actual.GameRows[gameRowId].UsersData[2]);
            AssertResultsByGameGameRowUserData(4, "Favorite", "ATL", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[3]);

            gameRowId = 8;
            Assert.AreEqual(4, actual.GameRows[gameRowId].UsersData.Count);
            AssertResultsByGameGameRowUserData(1, "Favorite", "DET", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[0]);
            AssertResultsByGameGameRowUserData(2, "Favorite", "DET", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[1]);
            AssertResultsByGameGameRowUserData(3, "Underdog", "MIN", 1, 2, 0, 0, actual.GameRows[gameRowId].UsersData[2]);
            AssertResultsByGameGameRowUserData(4, "Favorite", "DET", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[3]);

            gameRowId = 9;
            Assert.AreEqual(4, actual.GameRows[gameRowId].UsersData.Count);
            AssertResultsByGameGameRowUserData(1, "Favorite", "SEA", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[0]);
            AssertResultsByGameGameRowUserData(2, "Favorite", "SEA", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[1]);
            AssertResultsByGameGameRowUserData(3, "Favorite", "SEA", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[2]);
            AssertResultsByGameGameRowUserData(4, "Favorite", "SEA", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[3]);

            gameRowId = 10;
            Assert.AreEqual(4, actual.GameRows[gameRowId].UsersData.Count);
            AssertResultsByGameGameRowUserData(1, "Underdog", "PHI", 3, -3, 0, 0, actual.GameRows[gameRowId].UsersData[0]);
            AssertResultsByGameGameRowUserData(2, "Underdog", "PHI", 5, -5, 0, 0, actual.GameRows[gameRowId].UsersData[1]);
            AssertResultsByGameGameRowUserData(3, "Underdog", "PHI", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[2]);
            AssertResultsByGameGameRowUserData(4, "Favorite", "DAL", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[3]);

            gameRowId = 11;
            Assert.AreEqual(4, actual.GameRows[gameRowId].UsersData.Count);
            AssertResultsByGameGameRowUserData(1, "Favorite", "SF", 3, -3, 0, 0, actual.GameRows[gameRowId].UsersData[0]);
            AssertResultsByGameGameRowUserData(2, "Favorite", "SF", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[1]);
            AssertResultsByGameGameRowUserData(3, "Favorite", "SF", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[2]);
            AssertResultsByGameGameRowUserData(4, "Favorite", "SF", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[3]);

            gameRowId = 12;
            Assert.AreEqual(4, actual.GameRows[gameRowId].UsersData.Count);
            AssertResultsByGameGameRowUserData(1, "Underdog", "HOU", 3, 6, 0, 0, actual.GameRows[gameRowId].UsersData[0]);
            AssertResultsByGameGameRowUserData(2, "Underdog", "HOU", 1, 2, 0, 0, actual.GameRows[gameRowId].UsersData[1]);
            AssertResultsByGameGameRowUserData(3, "Underdog", "HOU", 1, 2, 0, 0, actual.GameRows[gameRowId].UsersData[2]);
            AssertResultsByGameGameRowUserData(4, "Favorite", "CHI", 1, -1, 0, 0, actual.GameRows[gameRowId].UsersData[3]);

            gameRowId = 13;
            Assert.AreEqual(4, actual.GameRows[gameRowId].UsersData.Count);
            AssertResultsByGameGameRowUserData(1, "Favorite", "PIT", 3, 3, 0, 0, actual.GameRows[gameRowId].UsersData[0]);
            AssertResultsByGameGameRowUserData(2, "Favorite", "PIT", 1, 1, 0, 0, actual.GameRows[gameRowId].UsersData[1]);
            AssertResultsByGameGameRowUserData(3, "Favorite", "PIT", 5, 5, 0, 0, actual.GameRows[gameRowId].UsersData[2]);
            AssertResultsByGameGameRowUserData(4, "Favorite", "PIT", 5, 5, 0, 0, actual.GameRows[gameRowId].UsersData[3]);

            Assert.AreEqual(5, actual.Totals[0], "Totals not equal");
            Assert.AreEqual(8, actual.Totals[1], "Totals not equal");
            Assert.AreEqual(13, actual.Totals[2], "Totals not equal");
            Assert.AreEqual(10, actual.Totals[3], "Totals not equal");

            Assert.AreEqual(0, actual.PotentialGains[0], "PotentialGains not equal");
            Assert.AreEqual(0, actual.PotentialGains[1], "PotentialGains not equal");
            Assert.AreEqual(0, actual.PotentialGains[2], "PotentialGains not equal");
            Assert.AreEqual(0, actual.PotentialGains[3], "PotentialGains not equal");

            Assert.AreEqual(0, actual.PotentialLosses[0], "PotentialLosses not equal");
            Assert.AreEqual(0, actual.PotentialLosses[1], "PotentialLosses not equal");
            Assert.AreEqual(0, actual.PotentialLosses[2], "PotentialLosses not equal");
            Assert.AreEqual(0, actual.PotentialLosses[3], "PotentialLosses not equal");
        }
コード例 #2
0
        public ResultsByGameViewModel BuildResultsByGameViewModel(int currentGameFilterId, ref string viewBagMessageToUser, List <User> users, List <GameSpread> gameSpreads, List <GameResult> gameResults, List <UserGameSelection> userGameSelections, List <UserGameResult> userGameResults, Team noBetTeam, Team noPicksTeam, Team noWinnerTeam)
        {
            #region validate inputs
            if (users == null)
            {
                throw new ArgumentNullException("users");
            }
            if (gameSpreads == null)
            {
                throw new ArgumentNullException("gameSpreads");
            }
            if (gameResults == null)
            {
                throw new ArgumentNullException("gameResults");
            }
            if (userGameSelections == null)
            {
                throw new ArgumentNullException("userGameSelections");
            }
            if (userGameResults == null)
            {
                throw new ArgumentNullException("userGameResults");
            }
            if (noBetTeam == null)
            {
                throw new ArgumentException("No Bet team was not found");
            }
            if (noPicksTeam == null)
            {
                throw new ArgumentException("No Picks team was not found");
            }
            if (noWinnerTeam == null)
            {
                throw new ArgumentException("No Winner team was not found");
            }

            // make sure all lists are for this gameFilterId
            var gameSpreadsBad = gameSpreads.FirstOrDefault(_ => _.Game.GameFilterId != currentGameFilterId);
            if (gameSpreadsBad != null)
            {
                throw new ArgumentOutOfRangeException("gameSpreadsBad", "Contains records from an incorrect GameFilterId");
            }

            var gameResultsBad = gameResults.FirstOrDefault(_ => _.GameSpread.Game.GameFilterId != currentGameFilterId);
            if (gameResultsBad != null)
            {
                throw new ArgumentOutOfRangeException("gameResultsBad", "Contains records from an incorrect GameFilterId");
            }

            var userGameSelectionsBad = userGameSelections.FirstOrDefault(_ => _.GameSpread.Game.GameFilterId != currentGameFilterId);
            if (userGameSelectionsBad != null)
            {
                throw new ArgumentOutOfRangeException("userGameSelectionsBad", "Contains records from an incorrect GameFilterId");
            }

            var userGameResultsBad = userGameResults.FirstOrDefault(_ => _.UserGameSelection.GameSpread.Game.GameFilterId != currentGameFilterId);
            if (userGameResultsBad != null)
            {
                throw new ArgumentOutOfRangeException("userGameResultsBad", "Contains records from an incorrect GameFilterId");
            }

            // make sure the lists are sorted correctly
            users              = users.OrderBy(_ => _.UserId).ToList();
            gameSpreads        = gameSpreads.OrderBy(_ => _.GameId).ToList();
            gameResults        = gameResults.OrderBy(_ => _.GameSpread.GameId).ToList();
            userGameSelections = userGameSelections.OrderBy(_ => _.GameSpread.GameId).ThenBy(_ => _.UserId).ToList();
            userGameResults    = userGameResults.OrderBy(_ => _.UserGameSelection.GameSpread.GameId).ThenBy(_ => _.UserGameSelection.UserId).ToList();
            #endregion

            var utilities = new ModelUtilities();
            var vm        = new ResultsByGameViewModel(currentGameFilterId);
            vm.Users = users;                                                       // add the users to the view model (this will be column headers on page)

            // loop through each game, creating the initial game row record
            foreach (var gameSpread in gameSpreads)
            {
                vm.GameRows.Add(new ResultsByGameGameRow(gameSpread, noWinnerTeam));
            }

            // now that the gamerows have been created, now lets update them with game results...if they exist
            foreach (var gameResult in gameResults)
            {
                var gameRow = vm.GameRows.FirstOrDefault(_ => _.GameSpreadId == gameResult.GameSpreadId);

                if (gameRow == null)
                {
                    throw new ArgumentException(string.Format("gameRow was not found for gameResult.GameSpreadId ({0})", gameResult.GameSpreadId));
                }
                else
                {
                    gameRow.UpdateWinner(gameResult);
                }
            }

            // need to add the user game selections in the correct order of each row (GameRows) and in the order of each column (Users)
            // loop through each gameRow and then...
            foreach (var gameRow in vm.GameRows)
            {
                // ...loop through each user and then...
                foreach (var user in users)
                {
                    // check to see if this user has made user selections already
                    var userGameSelection = userGameSelections.FirstOrDefault(_ => _.UserId == user.UserId && _.GameSpreadId == gameRow.GameSpreadId);
                    if (userGameSelection == null)
                    {
                        var gameSpread = gameSpreads.FirstOrDefault(_ => _.GameSpreadId == gameRow.GameSpreadId);

                        // the user hasn't made any selections yet...so create the default ones for that user
                        userGameSelection = utilities.CreateDefaultUserGameSelection(gameSpread, user, noBetTeam);
                    }

                    gameRow.AddUserDataSelection(userGameSelection, noBetTeam, noPicksTeam);
                }
            }

            // update any user game results if they exist
            foreach (var userGameResult in userGameResults)
            {
                var gameRow = vm.GameRows.FirstOrDefault(_ => _.GameSpreadId == userGameResult.UserGameSelection.GameSpreadId);

                if (gameRow == null)
                {
                    throw new ArgumentException(string.Format("gameRow was not found for userGameResult.UserGameSelection.GameSpreadId ({0})", userGameResult.UserGameSelection.GameSpreadId));
                }
                else
                {
                    var userData = gameRow.UsersData.FirstOrDefault(_ => _.UserGameSelectionId == userGameResult.UserGameSelectionId && _.UserId == userGameResult.UserGameSelection.UserId);
                    userData.UpdateResult(userGameResult);
                }
            }

            if (vm.GameRows.Count > 0)
            {
                // make sure each game has each user data in the same order
                // get the user order from the first item
                var userDataFirst = vm.GameRows[0].UsersData;

                // now check all the subsequent userGameResults
                for (int i = 1; i < vm.GameRows.Count; i++)
                {
                    var userDataNext = vm.GameRows[i].UsersData;

                    if (userDataFirst.Count != userDataNext.Count)
                    {
                        throw new ArgumentException(
                                  string.Format(
                                      "The number of users does not match GameSpreadId:{0} and GameSpreadId:{1} for UsersData",
                                      vm.GameRows[0].GameSpreadId,
                                      vm.GameRows[i].GameSpreadId));
                    }

                    // now that we know the lengths are equal, make sure each item is in the same
                    // userid order as the first
                    for (int x = 0; x < userDataNext.Count; x++)
                    {
                        if (userDataFirst[x].UserId != userDataNext[x].UserId)
                        {
                            throw new ArgumentException(
                                      string.Format(
                                          "The users (UserId:{2}, UserId:{3}) in position:{4} do not match for GameSpreadId:{0} and GameSpreadId:{1} for UsersData",
                                          vm.GameRows[0].GameSpreadId,
                                          vm.GameRows[i].GameSpreadId,
                                          userDataFirst[x].UserId,
                                          userDataNext[x].UserId,
                                          x));
                        }
                    }
                }


                // TODO Move this logic inside view model
                List <int> totals = new List <int>();
                List <int> gains  = new List <int>();
                List <int> losses = new List <int>();

                // calculate totals
                foreach (var user in users)
                {
                    int total = 0;
                    int gain  = 0;
                    int loss  = 0;
                    foreach (var gameRow in vm.GameRows)
                    {
                        total += gameRow.UsersData
                                 .Where(_ => _.UserId == user.UserId)
                                 .Sum(_ => _.Result);

                        gain += gameRow.UsersData
                                .Where(_ => _.UserId == user.UserId)
                                .Sum(_ => _.PotentialGain);

                        loss += gameRow.UsersData
                                .Where(_ => _.UserId == user.UserId)
                                .Sum(_ => _.PotentialLoss);
                    }

                    totals.Add(total);
                    gains.Add(gain);
                    losses.Add(loss);
                }

                vm.Totals          = totals;
                vm.PotentialGains  = gains;
                vm.PotentialLosses = losses;
            }
            else
            {
                viewBagMessageToUser = string.Format("Missing games for given GameFilterId:{0}", currentGameFilterId);
            }

            return(vm);
        }
コード例 #3
0
        public ActionResult GameFilter(int id = 0)
        {
            var    vm = new ResultsByGameViewModel(id);
            string viewBagMessageToUser = string.Empty;

            try
            {
                var userId = GetUserIdentityId();
                int currentGameFilterId = validateGameFilterId(id);
                SetViewBagGameFilter(currentGameFilterId);

                // get this users game selections for this game filter
                var thisUsersGameSelections = db.UserGameSelections
                                              .Where(_ => _.UserId == userId && _.GameSpread.Game.GameFilterId == currentGameFilterId)
                                              .ToList();

                // check to make sure he has saved/submitted his user selections
                if (thisUsersGameSelections == null || thisUsersGameSelections.Count == 0)
                {
                    viewBagMessageToUser = "******";
                }
                else
                {
                    //check to make sure all the games are saved
                    bool gamesSaved = true;

                    foreach (var userGameSelection in thisUsersGameSelections)
                    {
                        // if anyone saved is false, then it will be false
                        gamesSaved = gamesSaved || userGameSelection.Saved;
                    }

                    if (!gamesSaved)
                    {
                        viewBagMessageToUser = "******";
                    }
                    else
                    {
                        var users = db.Users.OrderBy(u => u.UserId).ToList();

                        var gameSpreads = db.GameSpreads
                                          .Where(_ => _.Game.GameFilterId == currentGameFilterId)
                                          .OrderBy(_ => _.GameId)
                                          .ToList();

                        var gameResults = db.GameResults
                                          .Include(gr => gr.GameSpread)
                                          .Include(gr => gr.GameSpread.Game)
                                          .Include(gr => gr.GameSpread.FavoriteTeam)
                                          .Include(gr => gr.GameSpread.UnderdogTeam)
                                          .Where(gr => gr.GameSpread.Game.GameFilterId == currentGameFilterId)
                                          .OrderBy(gr => gr.GameSpread.GameId)
                                          .ToList();

                        var userGameSelections = db.UserGameSelections
                                                 .Include(ugr => ugr.GameSpread)
                                                 .Include(ugr => ugr.GameSpread.Game)
                                                 .Where(ugr => ugr.GameSpread.Game.GameFilterId == currentGameFilterId)
                                                 .OrderBy(ugr => ugr.GameSpread.GameId)
                                                 .ThenBy(ugr => ugr.UserId)
                                                 .ToList();

                        var userGameResults = db.UserGameResults
                                              .Include(ugr => ugr.UserGameSelection)
                                              .Include(ugr => ugr.UserGameSelection.GameSpread)
                                              .Include(ugr => ugr.UserGameSelection.GameSpread.Game)
                                              .Where(ugr => ugr.UserGameSelection.GameSpread.Game.GameFilterId == currentGameFilterId)
                                              .OrderBy(ugr => ugr.UserGameSelection.GameSpread.GameId)
                                              .ThenBy(ugr => ugr.UserGameSelection.UserId)
                                              .ToList();

                        var noBetTeam = db.Teams.FirstOrDefault(_ => _.TeamLongName == "No Bet");

                        if (noBetTeam == null)
                        {
                            throw new ArgumentException("No Bet team was not found");
                        }

                        var noWinnerTeam = db.Teams.FirstOrDefault(_ => _.TeamLongName == "No Winner");

                        if (noWinnerTeam == null)
                        {
                            throw new ArgumentException("No Winner team was not found");
                        }

                        var noPicksTeam = db.Teams.FirstOrDefault(_ => _.TeamLongName == "No Picks");

                        if (noPicksTeam == null)
                        {
                            throw new ArgumentException("No Picks team was not found");
                        }

                        vm = BuildResultsByGameViewModel(currentGameFilterId, ref viewBagMessageToUser, users, gameSpreads, gameResults, userGameSelections, userGameResults, noBetTeam, noPicksTeam, noWinnerTeam);
                    }
                }

                ViewBag.MessageToUser = viewBagMessageToUser;
            }
            catch (Exception ex)
            {
                ViewBag.MessageToUser = string.Format("Sorry an error occurred. Please let the admin know. Error:{0}", ex.Message);
            }

            return(View(vm));
        }
コード例 #4
0
        public void WhenTheViewModelIsBuilt()
        {
            ResultsByGameController controller = new ResultsByGameController();

            actual = controller.BuildResultsByGameViewModel(gameFilterId, ref viewBagMessageToUser, users, gameSpreads, gameResults, userGameSelections, userGameResults, noBetTeam, noPicksTeam, noWinnerTeam);
        }