Example #1
0
        private static bool SortTiedPicks(List<AllPicksViewModel> listAllPicks, AllPicksViewModel masterPicks, int indexToCheck)
        {
            // get all picks with same points as indexToCheck
            var tiedPicks = listAllPicks.Where(p => p.CorrectPicks == listAllPicks[indexToCheck].CorrectPicks).ToList();
            if (tiedPicks.Count == 1)
            {
                return false;
            }

            // we have some tied picks
            // RULE: The person closest to the Monday Night score will be the winner. If there is still a tie then under beats over
            tiedPicks = tiedPicks.OrderBy(p => Math.Abs(p.CombinedScore.GetValueOrDefault(0) - masterPicks.CombinedScore.GetValueOrDefault(0))
                                        + (p.CombinedScore.GetValueOrDefault(0) < masterPicks.CombinedScore.GetValueOrDefault(0) ? 0.0 : 0.5)).ToList();

            // reset the rank and re-position them in main list
            var newRank = indexToCheck + 1;
            for (var i = 0; i < tiedPicks.Count; i++)
            {
                var tiedPick = tiedPicks[i];

                // if combined score is the same, rank stays the same
                if (i > 0 && tiedPick.CombinedScore != tiedPicks[i - 1].CombinedScore)
                {
                    // otherwise reset to what it would have been (e.g. if we had two rank 1, then the third would be rank 3)
                    newRank = i + indexToCheck + 1;
                }

                tiedPick.Rank = newRank;

                listAllPicks.Remove(tiedPick);
                listAllPicks.Insert(i + indexToCheck, tiedPick);
            }

            return true;
        }
Example #2
0
        private static AllPicksViewModel ForUserFromPicks(List<PickViewModel> picks, UserListViewModel user, List<ScheduleViewModel> schedules, AllPicksViewModel masterPicks)
        {
            var model = new AllPicksViewModel
            {
                User = user,
                CorrectPicks = 0
            };

            // add all schedules with null pick
            foreach (var schedule in schedules.OrderBy(s => s.Date).ThenBy(s => s.Id))
            {
                model.PickedTeams.Add(schedule.Id, null);
            }

            if (picks != null)
            {
                // only add the teams for locked games
                foreach (var pick in picks.Where(p => p.User.Id == user.Id && !p.CanPick))
                {
                    var userPick = pick.PickHomeTeam.GetValueOrDefault(false) ? pick.Schedule.HomeTeam : pick.Schedule.AwayTeam;
                    model.PickedTeams[pick.Schedule.Id] = userPick;
                    if (pick.Schedule.RequireScore)
                    {
                        model.CombinedScore = pick.CombinedScore.GetValueOrDefault(0);
                    }

                    if (masterPicks != null)
                    {
                        // find the master pick for this schedule
                        var masterPick = masterPicks.PickedTeams.ContainsKey(pick.Schedule.Id) ? masterPicks.PickedTeams[pick.Schedule.Id] : null;
                        if (masterPick != null && masterPick.Id == userPick.Id)
                        {
                            // match
                            model.CorrectPicks++;
                        }
                    }
                }
            }

            return model;
        }