Exemplo n.º 1
0
        public ActionResult EclecticLeagueTable(int courseID, int compID)
        {
            // Get Players in this competition with matching Home Course and populate the BestScoreView Model
            var getPlayers = (from cp in db.CompPlayers
                              join ur in db.Users on cp.UserID equals ur.UserID
                              join pr in db.Profiles on ur.UserID equals pr.UserID
                              where cp.CompID == compID && pr.HomeClubID == courseID
                              select new BestScoreView
            {
                playerName = ur.UserName,
                compPlayerID = cp.CompPlayerID
            }).ToList();

            // Loop through each Player and get their BEST List of Scores
            int loopcount = getPlayers.Count();

            for (int i = 0; i < loopcount; i++)
            {
                int compPlayerID = getPlayers[i].compPlayerID;

                // Check player has posted a round
                var playersRndsCount = (from pr in db.CompScores
                                        where pr.CompPlayerID == compPlayerID && pr.CompID == compID && pr.CourseID == courseID
                                        select pr).Count();

                if (playersRndsCount > 0)
                {
                    List <int> bestScores = pStats.BestScoreList(compPlayerID, courseID);
                    getPlayers[i].Hole1  = bestScores[0];
                    getPlayers[i].Hole2  = bestScores[1];
                    getPlayers[i].Hole3  = bestScores[2];
                    getPlayers[i].Hole4  = bestScores[3];
                    getPlayers[i].Hole5  = bestScores[4];
                    getPlayers[i].Hole6  = bestScores[5];
                    getPlayers[i].Hole7  = bestScores[6];
                    getPlayers[i].Hole8  = bestScores[7];
                    getPlayers[i].Hole9  = bestScores[8];
                    getPlayers[i].Hole10 = bestScores[9];
                    getPlayers[i].Hole11 = bestScores[10];
                    getPlayers[i].Hole12 = bestScores[11];
                    getPlayers[i].Hole13 = bestScores[12];
                    getPlayers[i].Hole14 = bestScores[13];
                    getPlayers[i].Hole15 = bestScores[14];
                    getPlayers[i].Hole16 = bestScores[15];
                    getPlayers[i].Hole17 = bestScores[16];
                    getPlayers[i].Hole18 = bestScores[17];

                    // Number of Rounds
                    getPlayers[i].NumberOfRnds = playersRndsCount;

                    // Get Total Score
                    getPlayers[i].TotalScore = bestScores.Sum();

                    // Get Par Score
                    int parScore = getPlayers[i].TotalScore - cInfo.GetCoursePar(courseID, "Yellow");
                    if (parScore == 0)
                    {
                        getPlayers[i].ParScore = "E";
                    }
                    else if (parScore > 0)
                    {
                        getPlayers[i].ParScore = "+" + parScore.ToString();
                    }
                    else
                    {
                        getPlayers[i].ParScore = parScore.ToString();
                    }
                }
            }
            ;

            // Sort List for table
            // Sort list into Points Descending and apply current Position
            var sortedPlayers = (from sp in getPlayers
                                 where sp.TotalScore > 0
                                 orderby sp.TotalScore, sp.playerName
                                 select sp).ToList();

            for (int i = 0; i < sortedPlayers.Count(); i++)
            {
                sortedPlayers[i].currentPosition = i + 1;
            }


            // Get list of hole Pars for this course
            List <int> parList = new List <int>();

            for (int i = 1; i < 19; i++)
            {
                parList.Add(cInfo.GetHolePar(i, courseID, "Yellow"));
            }
            ViewBag.ParList = parList;

            // Get course Name for title
            ViewBag.Course   = cInfo.GetCourseName(courseID);
            ViewBag.CompID   = compID;
            ViewBag.CourseID = courseID;

            // Get Club Names For Drop Down List
            var courseInfo = new CourseInfo();

            ViewBag.CourseList = courseInfo.GetCourseList();

            // Return List to View
            return(PartialView("_EclecticLeagueTable", sortedPlayers));
        }