Example #1
0
        internal static void UpdateEntryFeeFlag(int simpleUserId)
        {
            ApplicationDbContext _db      = new ApplicationDbContext();
            FootballPoolUsers    thisUser = _db.FootballPoolUser.Where(u => u.simpleUserId == simpleUserId).First();

            thisUser.hasPaid          = true;
            _db.Entry(thisUser).State = System.Data.Entity.EntityState.Modified;
            _db.SaveChanges();
        }
Example #2
0
        private static ApplicationDbContext AddFootballUser(int simpleUserId, string userName, ApplicationUser thisUser, ApplicationDbContext db)
        {
            FootballPoolUsers thisFootballUser = new FootballPoolUsers()
            {
                simpleUserId = simpleUserId, userName = userName, signedUpDate = DateTime.Now, hasPaid = false
            };
            var userExistsAlready = db.FootballPoolUser.Where(u => u.simpleUserId == simpleUserId).FirstOrDefault();

            if (userExistsAlready == null)
            {
                try
                {
                    LoggerFactory.LogInfo("AddFootballUser", "Attempting to add football user", "Username: "******"AddFootballUser", "Successfully added football user.", "Username: "******"AddFootballUser", "Attempting to add football user failed: " + string.Format("Message: {0} more details: {1}", e.Message, e.InnerException.Message), e.StackTrace, Convert.ToString(simpleUserId));
                }
            }
            return(db);
        }
Example #3
0
        internal static void GenerateUserScores(int weekId)
        {
            ApplicationDbContext _db = new ApplicationDbContext();
            var simpleUserIdList     = _db.Users.Where(u => u.isPlayingFootballPool == true).Select(u => u.simpleUserId).ToList();
            var winningTeamsIdList   = _db.FootballGame.Where(fg => fg.weekId == weekId).Select(fg => fg.winningTeamId).ToList();
            var numOfGamesThisWeek   = _db.FootballGame.Where(g => g.weekId == weekId).ToList().Count;

            foreach (var userId in simpleUserIdList)
            {
                decimal           userScoreThisWeek   = 0.00M;
                decimal           bonusPointsThisWeek = 0.00M;
                var               lossesThisWeek      = 0;
                var               winsThisWeek        = 0;
                FootballPoolUsers thisUser            = _db.FootballPoolUser.Where(u => u.simpleUserId == userId).First();
                var               thisUsersPicks      = _db.FootballPoolUserPicks.OrderBy(up => up.gameId).Where(up => up.simpleUserId == userId && up.weekId == weekId).Select(up => up.pick).ToList();
                //var thisUsersPicks = _db.FootballPoolUserPicks.Where(up => up.simpleUserId == userId && up.weekId == weekId).Select(up => up.pick).ToList();
                var gamesScored = _db.FootballGame.Where(fg => fg.winningTeamId != 0 && fg.lossingTeamId != 0 && fg.weekId == weekId).ToList().Count();
                if (thisUsersPicks.Count > 0)
                {
                    //need to compare user list to the winning list
                    for (int i = 0; i < numOfGamesThisWeek; i++)
                    {
                        if (winningTeamsIdList[i] != 0)//game has been scored - winning Id = 0 means game has not been scored so it should not count towards user score generation
                        {
                            if (thisUsersPicks[i] == winningTeamsIdList[i])
                            {
                                userScoreThisWeek += 1.00M;
                                winsThisWeek      += 1;
                            }
                            else
                            {
                                lossesThisWeek += 1;
                            }
                        }
                    }

                    bonusPointsThisWeek = Math.Floor(userScoreThisWeek / 5.00M);
                    bonusPointsThisWeek = (bonusPointsThisWeek * 0.25M);
                }
                else
                {
                    //user did not make their picks at all or at least what has been scored. find out how many games have been scored?
                    lossesThisWeek = gamesScored;
                }
                //Add to weekly score table
                FootballPoolUserWeeklyScores userWeeklyScoreObj = _db.FootballPoolUserWeeklyScores.Where(up => up.weekId == weekId && up.simpleUserId == userId).FirstOrDefault();
                if (userWeeklyScoreObj == null)
                {
                    //doesn't exsist so add it
                    FootballPoolUserWeeklyScores weeklyScore = new FootballPoolUserWeeklyScores()
                    {
                        score = userScoreThisWeek + bonusPointsThisWeek, simpleUserId = userId, weekId = weekId, wins = winsThisWeek, losses = lossesThisWeek
                    };
                    _db.FootballPoolUserWeeklyScores.Add(weeklyScore);
                    _db.SaveChanges();
                }
                else
                {
                    //exsists so update the score record
                    userWeeklyScoreObj.wins             = winsThisWeek;
                    userWeeklyScoreObj.losses           = lossesThisWeek;
                    userWeeklyScoreObj.score            = userScoreThisWeek + bonusPointsThisWeek;
                    _db.Entry(userWeeklyScoreObj).State = System.Data.Entity.EntityState.Modified;
                    _db.SaveChanges();
                }


                //update user table with score, represents all weeks
                thisUser.userScore = _db.FootballPoolUserWeeklyScores.Where(us => us.simpleUserId == userId).Select(up => up.score).Sum();

                //determine wins
                thisUser.win = _db.FootballPoolUserWeeklyScores.Where(us => us.simpleUserId == userId).Select(up => up.wins).Sum();

                //determine losses
                thisUser.loss = _db.FootballPoolUserWeeklyScores.Where(us => us.simpleUserId == userId).Select(up => up.losses).Sum();


                _db.Entry(thisUser).State = System.Data.Entity.EntityState.Modified;
                _db.SaveChanges();
            }
        }