示例#1
0
        public UserGameSelection CreateDefaultUserGameSelection(GameSpread gameSpread, User user, Team noBetTeam)
        {
            if (gameSpread == null)
            {
                throw new ArgumentNullException("gameSpread");
            }
            if (noBetTeam == null)
            {
                throw new ArgumentNullException("noBetTeam");
            }
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            // create the userGameSelection with No Bets
            var userGameSelection = new UserGameSelection()
            {
                Bet          = 0,
                GameSpreadId = gameSpread.GameSpreadId,
                PickTeamId   = noBetTeam.TeamId,
                GameSpread   = gameSpread,
                PickTeam     = noBetTeam,
                UserId       = user.UserId,
                User         = user,
                Saved        = false
            };

            return(userGameSelection);
        }
示例#2
0
        public UserGameSelection CreateDefaultUserGameSelection(GameSpread gameSpread, User user, Team noBetTeam)
        {
            if (gameSpread == null) throw new ArgumentNullException("gameSpread");
            if (noBetTeam == null) throw new ArgumentNullException("noBetTeam");
            if (user == null) throw new ArgumentNullException("user");

            // create the userGameSelection with No Bets
            var userGameSelection = new UserGameSelection()
                                         {
                                             Bet = 0,
                                             GameSpreadId = gameSpread.GameSpreadId,
                                             PickTeamId = noBetTeam.TeamId,
                                             GameSpread = gameSpread,
                                             PickTeam = noBetTeam,
                                             UserId = user.UserId,
                                             User = user,
                                             Saved = false
                                         };

            return userGameSelection;
        }
示例#3
0
 public void AddUserDataSelection(UserGameSelection userGameSelection, Team noBetTeam, Team noPicksTeam)
 {
     UsersData.Add(new ResultsByGameGameRowUserData(userGameSelection, noBetTeam, noPicksTeam));
 }
示例#4
0
        public ResultsByGameGameRowUserData(UserGameSelection userGameSelection, Team noBetTeam, Team noPicksTeam)
        {
            var found = false;

            if (userGameSelection == null) throw new ArgumentException("userGameSelection is null");

            UserGameSelectionId = userGameSelection.UserGameSelectionId;
            UserId = userGameSelection.UserId;

            if (userGameSelection.GameSpread == null) throw new ArgumentException("userGameSelection.GameSpread is null");
            if (userGameSelection.PickTeam == null) throw new ArgumentException("userGameSelection.PickTeam is null");
            if (userGameSelection.GameSpread.FavoriteTeamId == userGameSelection.GameSpread.UnderdogTeamId) throw new ArgumentException(string.Format("favoriteTeamId ({0}) cannot equal underdogTeamId ({1})", userGameSelection.GameSpread.FavoriteTeamId, userGameSelection.GameSpread.UnderdogTeamId));
            if (userGameSelection.GameSpread.FavoriteTeamId == noBetTeam.TeamId) throw new ArgumentException(string.Format("favoriteTeamId ({0}) cannot equal noBetTeamId ({1})", userGameSelection.GameSpread.FavoriteTeamId, noBetTeam.TeamId));
            if (userGameSelection.GameSpread.FavoriteTeamId == noPicksTeam.TeamId) throw new ArgumentException(string.Format("favoriteTeamId ({0}) cannot equal noPicksTeamId ({1})", userGameSelection.GameSpread.FavoriteTeamId, noPicksTeam.TeamId));
            if (userGameSelection.GameSpread.UnderdogTeamId == noBetTeam.TeamId) throw new ArgumentException(string.Format("underdogTeamId ({0}) cannot equal noBetTeamId ({1})", userGameSelection.GameSpread.UnderdogTeamId, noBetTeam.TeamId));
            if (userGameSelection.GameSpread.UnderdogTeamId == noPicksTeam.TeamId) throw new ArgumentException(string.Format("underdogTeamId ({0}) cannot equal noPicksTeamId ({1})", userGameSelection.GameSpread.UnderdogTeamId, noPicksTeam.TeamId)); ;
            if (noBetTeam.TeamId == noPicksTeam.TeamId) throw new ArgumentException(string.Format("noBetTeamId ({0}) cannot equal noPicksTeamId ({1})", noBetTeam.TeamId, noPicksTeam.TeamId));

            if (userGameSelection.PickTeamId == userGameSelection.GameSpread.FavoriteTeamId)
            {
                PickedFavorite = true;
                found = true;
            }
            else if (userGameSelection.PickTeamId == userGameSelection.GameSpread.UnderdogTeamId)
            {
                PickedUnderdog = true;
                found = true;
            }
            else if (userGameSelection.PickTeamId == noBetTeam.TeamId)
            {
                PickedNoBet = true;
                found = true;
            }
            else if (userGameSelection.PickTeamId == noPicksTeam.TeamId)
            {
                PickedNoPicks = true;
                found = true;
            }

            if (found == false)
            {
                throw new ArgumentException(string.Format("pickTeamId ({0}) not found", userGameSelection.PickTeamId));
            }

            Pick = userGameSelection.PickTeam.TeamShortName;
            Bet = userGameSelection.Bet;
            Result = 0;

            if (PickedUnderdog)
            {
                PotentialGain = userGameSelection.Bet * 2; //TODO remove hardcoding and factor in upset bonus
            }
            else
            {
                PotentialGain = userGameSelection.Bet;
            }

            PotentialLoss = userGameSelection.Bet * -1;
        }
示例#5
0
        public List<UserGameResult> CalculateUserGameResults(int userId, int gameFilterId, List<GameResult> thisGameFiltersGameResults, List<UserGameSelection> thisUsersGameSelectionsForThisGameFilter, Team noBetPickTeam, int extraPointFactorPerBetOverMin)
        {
            string logProcess = "AdminController.GameResultProcessing.BuildUserGameResults.CalculateUserGameResults";
            try
            {
                var userGameResults = new List<UserGameResult>();

                var wrongGameFilterIdCount = thisGameFiltersGameResults
                                                    .Where(gr => gr.GameSpread.Game.GameFilterId != gameFilterId)
                                                    .Count();

                if (wrongGameFilterIdCount > 0)
                {
                    throw new ArgumentException(string.Format("The game result list has records for the wrong game filter ({0})", wrongGameFilterIdCount));
                }

                var wrongUserIdCount = thisUsersGameSelectionsForThisGameFilter
                                .Where(ugs => ugs.UserId != userId)
                                .Count();

                wrongGameFilterIdCount = thisUsersGameSelectionsForThisGameFilter
                                                    .Where(ugs => ugs.GameSpread.Game.GameFilterId != gameFilterId)
                                                    .Count();

                if (wrongUserIdCount > 0 || wrongGameFilterIdCount > 0)
                {
                    throw new ArgumentException(string.Format("The user game selection list has records for the wrong user ({0}) and/or game filter ({1})", wrongUserIdCount, wrongGameFilterIdCount));
                }

                // loop through each game to see if user was correct or not
                foreach (var gameResult in thisGameFiltersGameResults)
                {
                    var userGameSelection = thisUsersGameSelectionsForThisGameFilter.FirstOrDefault(ugs => ugs.GameSpreadId == gameResult.GameSpreadId);

                    if (userGameSelection == null)
                    {
                        string toLog = string.Format("UserId:{0} is missing a selection for GameSpreadId:{1}", userId, gameResult.GameSpreadId);
                        logMessages.Add(new Log() { GameDateTime = DateTime.Now, Type = "Warning", Process = logProcess, Message = toLog });

                        // create a no bet usergameselection
                        userGameSelection = new UserGameSelection() { UserId = userId, GameSpreadId = gameResult.GameSpreadId, PickTeamId = noBetPickTeam.TeamId, Bet = 0 };

                        //TODO see if no UserGameSelectionId will cause error on save
                        userGameResults.Add(new UserGameResult()
                        {
                            //UserGameSelectionId = userGameSelection.UserGameSelectionId,
                            UserGameSelection = userGameSelection,
                            BetResult = 0,  // no result since it is a no bet
                            BetPoints = 0   // no points since it is a no bet
                        });
                    }
                    else
                    {
                        if (userGameSelection.PickTeamId == noBetPickTeam.TeamId)
                        {
                            //user didn't bet, he picked no bet
                            userGameResults.Add(new UserGameResult()
                            {
                                UserGameSelectionId = userGameSelection.UserGameSelectionId,
                                UserGameSelection = userGameSelection,
                                BetResult = 0,  // no result since it is a no bet
                                BetPoints = 0   // no points since it is a no bet
                            });
                        }
                        else
                        {
                            //user picked a team, betted on this game
                            //determine if they won the bet
                            var result = userGameSelection.PickTeamId == gameResult.WinnerTeamId;
                            var underdog = userGameSelection.PickTeamId == gameResult.GameSpread.UnderdogTeamId;

                            var betPoints = 0;

                            if (underdog && result)
                            {   // only if picked the underdog and won, do you get the extra points
                                betPoints = userGameSelection.Bet + (userGameSelection.Bet * extraPointFactorPerBetOverMin);
                            }
                            else
                            {
                                betPoints = userGameSelection.Bet;
                            }

                            if (result)
                            {
                                //won the bet
                                userGameResults.Add(new UserGameResult()
                                {
                                    UserGameSelectionId = userGameSelection.UserGameSelectionId,
                                    UserGameSelection = userGameSelection,
                                    BetResult = 1,  // bet was won
                                    BetPoints = betPoints
                                });
                            }
                            else
                            {
                                //lost the bet
                                userGameResults.Add(new UserGameResult()
                                {
                                    UserGameSelectionId = userGameSelection.UserGameSelectionId,
                                    UserGameSelection = userGameSelection,
                                    BetResult = -1,  // bet was won
                                    BetPoints = betPoints * -1
                                });
                            }
                        }
                    }
                }

                return userGameResults;
            }
            catch (Exception ex)
            {
                logMessages.Add(new Log() { GameDateTime = DateTime.Now, Type = "Error", Process = logProcess, Message = ex.Message });
                throw;
            }
            finally
            {
                logMessages.Add(new Log() { GameDateTime = DateTime.Now, Type = "Info", Process = logProcess, Message = "Ending" });
            }
        }
示例#6
0
 public SelectionGameRow()
 {
     UserGameSelection = new UserGameSelection();
     SelectionPicker = new SelectionPicker();
     BetPickers = new List<BetPicker>();
 }