Ejemplo n.º 1
0
        // GET: Scores
        public ActionResult Index(int compID, int compPlayerID)
        {
            CompMain cMain = db.CompMains.Find(compID);

            var playerRnds = from pr in db.CompScores
                             join cm in db.CourseMains on pr.CourseID equals cm.CourseID
                             where pr.CompID == compID && pr.CompPlayerID == compPlayerID
                             orderby pr.RndDate
                             select new RndSummary {
                CompScoreID = pr.CompScoreID, RndDate = pr.RndDate, ClubName = cm.ClubName, TeeColour = pr.TeeColour, RndPoints = pr.TotalPoints, CourseID = pr.CourseID, SSS = pr.SSS
            };

            // Get and store the Total Score for each round
            List <RndSummary> playerRndsIncScore = new List <RndSummary>();
            int RndNumber = 1;

            foreach (var item in playerRnds)
            {
                var RndIncScore = new RndSummary();
                RndIncScore.CompScoreID  = item.CompScoreID;
                RndIncScore.RndDate      = item.RndDate;
                RndIncScore.ClubName     = item.ClubName;
                RndIncScore.TeeColour    = item.TeeColour;
                RndIncScore.RndPoints    = item.RndPoints;
                RndIncScore.RndScore     = rndSum.GetRndScore(item.CompScoreID);
                RndIncScore.CourseID     = item.CourseID;
                RndIncScore.SSS          = item.SSS;
                RndIncScore.NETRndPoints = Convert.ToInt32(item.RndPoints - (cInfo.GetCoursePar(RndIncScore.CourseID, RndIncScore.TeeColour) - RndIncScore.SSS));
                RndIncScore.RndNumber    = RndNumber;
                RndNumber += 1;
                playerRndsIncScore.Add(RndIncScore);
            }

            // *** Sort rnds into Points Order ***
            List <RndSummary> sortedRnds = playerRndsIncScore.OrderByDescending(o => o.NETRndPoints).ToList();

            // Get Competition Name and Player Name
            ViewBag.PlayerName = pStats.GetPlayerName(compPlayerID);
            ViewBag.CompName   = cMain.CompName;
            ViewBag.CompID     = cMain.CompID;

            ViewBag.RndSummary = sortedRnds;
            return(View());
        }
Ejemplo n.º 2
0
        // GET: Scores
        public ActionResult PlayerRnds(int compID, int compPlayerID, string sortBy)
        {
            CompMain cMain = db.CompMains.Find(compID);

            var playerRnds = from pr in db.CompScores
                             join cm in db.CourseMains on pr.CourseID equals cm.CourseID
                             where pr.CompID == compID && pr.CompPlayerID == compPlayerID
                             orderby pr.RndDate
                             select new RndSummary
            {
                CompScoreID = pr.CompScoreID,
                RndDate     = pr.RndDate,
                ClubName    = cm.ClubName,
                TeeColour   = pr.TeeColour,
                RndPoints   = pr.TotalPoints,
                CourseID    = pr.CourseID,
                SSS         = pr.SSS,
                Handicap    = pr.PlayerHcap
            };

            // Get and store the Total Score for each round
            List <RndSummary> playerRndsIncScore = new List <RndSummary>();
            int RndNumber = 1;

            foreach (var item in playerRnds)
            {
                var RndIncScore = new RndSummary();
                RndIncScore.CompScoreID  = item.CompScoreID;
                RndIncScore.RndDate      = item.RndDate;
                RndIncScore.ClubName     = item.ClubName;
                RndIncScore.TeeColour    = item.TeeColour;
                RndIncScore.Handicap     = item.Handicap;
                RndIncScore.RndPoints    = item.RndPoints;
                RndIncScore.RndScore     = rndSum.GetRndScore(item.CompScoreID);
                RndIncScore.CourseID     = item.CourseID;
                RndIncScore.SSS          = item.SSS;
                RndIncScore.NETRndPoints = Convert.ToInt32(item.RndPoints - (cInfo.GetCoursePar(RndIncScore.CourseID, RndIncScore.TeeColour) - RndIncScore.SSS));
                RndIncScore.RndNumber    = RndNumber;
                RndNumber += 1;
                playerRndsIncScore.Add(RndIncScore);
            }

            // if Rnd Count > 10 then sort by Rnd Points descending and discard the rnds after the 10th
            if (RndNumber > 10)
            {
                // *** Sort rnds into Points Order ***
                List <RndSummary> checksortedRnds = playerRndsIncScore.OrderByDescending(o => o.NETRndPoints).ToList();
                int c = 0;
                foreach (var item in checksortedRnds)
                {
                    c += 1;
                    if (c > 10)
                    {
                        item.Discard = true;
                    }
                }
            }

            List <RndSummary> sortedRnds;

            if (sortBy == "Points")
            {
                // *** Sort rnds into Points Order ***
                sortedRnds = playerRndsIncScore.OrderByDescending(o => o.NETRndPoints).ToList();
            }
            else
            {
                // *** Sort rnds into Date Order ***
                sortedRnds = playerRndsIncScore.OrderBy(o => o.RndDate).ToList();
            }


            // Get Competition Name, Player Name, Current Handicap and Player Photo
            ViewBag.PlayerName   = pStats.GetPlayerName(compPlayerID);
            ViewBag.PlayerPhoto  = pStats.GetPlayerPhoto(compPlayerID);
            ViewBag.CurrentHCap  = pStats.CurrentHcap(compPlayerID);
            ViewBag.PlayerHomeID = pStats.HomeClubID(compPlayerID);
            ViewBag.CompName     = cMain.CompName;
            ViewBag.CompID       = cMain.CompID;
            ViewBag.CompPlayerID = compPlayerID;
            ViewBag.SortBy       = sortBy;

            ViewBag.RndSummary = sortedRnds;
            return(View());
        }