BolfTracker.Web.GamePanelViewModel.GetCurrentHole C# (CSharp) Method

GetCurrentHole() public method

public GetCurrentHole ( ) : int
return int
        public int GetCurrentHole()
        {
            _currentHole = 1;

            if (Shots.Any())
            {
                _currentHole = Shots.Max(s => s.Hole.Id);
                var holeShots = Shots.Where(s => s.Hole.Id == _currentHole.Value).ToList();

                if (_currentHole.Value == 1)
                {
                    // If we are on the first hole, there's no way of knowing when to go to the next hole
                    // because we don't know how many players are going (unless it's been pushed on 1)
                    if (holeShots.Count(s => s.Attempts == 1 && s.ShotMade) > 1)
                    {
                        _currentHole += 1;
                        return _currentHole.Value;
                    }
                    else
                    {
                        return _currentHole.Value;
                    }
                }
                else
                {
                    // If the hole was pushed on 1, go to the next hole
                    if (holeShots.Count(s => s.Attempts == 1 && s.ShotMade) > 1)
                    {
                        _currentHole++;
                        return _currentHole.Value;
                    }

                    var totalPlayers = GetCurrentActivePlayers(ActivePlayers, includeOvertime: false).Count();

                    // If everyone has gone, go to the next hole
                    if (holeShots.Count() == totalPlayers)
                    {
                        _currentHole++;
                    }

                    // TODO: This needs to change to a MAX function for hole number when the new hole/overtime logic is added
                    if (_currentHole.Value >= 10)
                    {
                        var newHoleShots = Shots.Where(s => s.Hole.Id == _currentHole.Value).ToList();

                        if (newHoleShots.Count(s => s.Attempts == 1 && s.ShotMade) > 1 || HoleIsPushed(_currentHole.Value))
                        {
                            // Two people have made the shot in 1, move on to the next
                            _currentHole++;
                            return _currentHole.Value;
                        }
                        else
                        {
                            // NOTE: Anything going off of x.Player.Shots is runs a shitload of queries... avoid
                            var playersWhoCanWin = GetPlayersWhoCanWin(_currentHole.Value).Where(g => Shots.Count(s => s.Hole.Id == _currentHole.Value && !s.ShotMade && s.Player.Id == g.Player.Id) == 0);

                            if (playersWhoCanWin.Count() == 0)
                            {
                                _currentHole++;
                                return _currentHole.Value;
                            }
                            else
                            {
                                return _currentHole.Value;
                            }
                        }
                    }
                }
            }

            return _currentHole.Value;
        }