示例#1
0
        // GET: CompMains/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CompMain compMain = db.CompMains.Find(id);

            if (compMain == null)
            {
                return(HttpNotFound());
            }

            // Create Format DDL Options
            var CompFormatList = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "Stableford", Selected = true
                },
            };

            ViewBag.FormatList = CompFormatList;

            return(View(compMain));
        }
示例#2
0
        // GET: Scores/Edit/5
        public ActionResult Edit(int?CompScoreID)
        {
            if (CompScoreID == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CompScore compScore = db.CompScores.Find(CompScoreID);

            ViewBag.PHcap      = compScore.PlayerHcap;
            ViewBag.PlayerName = pStats.GetPlayerName(compScore.CompPlayerID);

            CourseMain courseM = db.CourseMains.Find(compScore.CourseID);

            ViewBag.CourseName = courseM.ClubName;

            CompMain cMain = db.CompMains.Find(compScore.CompID);

            ViewBag.CompName = cMain.CompName;

            // Get the Course Par
            ViewBag.CoursePar = cInfo.GetCoursePar(compScore.CourseID, compScore.TeeColour);

            // Get the NET Points (Gross Points - (CoursePar - SSS))
            ViewBag.NetPoints = compScore.TotalPoints - (ViewBag.CoursePar - compScore.SSS);

            if (compScore == null)
            {
                return(HttpNotFound());
            }
            return(View(compScore));
        }
示例#3
0
 public ActionResult Edit([Bind(Include = "CompID,CompName,DateStart,DateEnd,Format")] CompMain compMain)
 {
     if (ModelState.IsValid)
     {
         db.Entry(compMain).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(compMain));
 }
示例#4
0
        public ActionResult InterClubTable(int compID)
        {
            CompMain competition = db.CompMains.Find(compID);

            if (competition == null)
            {
                return(HttpNotFound());
            }

            //Gather info for InterClubSummary model
            InterClubInfo inclubInfo = new InterClubInfo();
            var           courseM    = (from cm in db.CourseMains
                                        orderby cm.ClubName
                                        select new InterClubSummary
            {
                ClubName = cm.ClubName,
                courseID = cm.CourseID
            }).ToList();

            // Loop through clubs to calulate and store No of Players, No of Rounds, Total Points and Average Points in InterClub Summary
            foreach (var item in courseM)
            {
                // Number of Players
                item.NumberOfPlayers = inclubInfo.GetNumberOfPlayers(item.courseID, compID);

                // Number of Rounds
                item.NumberOfRnds = inclubInfo.GetNumberOfRnds(item.courseID, compID);

                // Total Points
                item.TotalPoints = inclubInfo.GetTotalPoints(item.courseID, compID);

                // Average Points
                if (item.NumberOfRnds > 0 && item.TotalPoints > 0)
                {
                    item.AveragePoints = Math.Round((decimal)item.TotalPoints / item.NumberOfRnds, 2);
                }
            }

            //Sort into Average Points descending
            var sortedClubTable = (from st in courseM
                                   orderby st.AveragePoints descending
                                   select st).ToList();
            int p = 0;

            foreach (var item in sortedClubTable)
            {
                p            += 1;
                item.Position = p;
            }

            ViewBag.CompName = competition.CompName;
            ViewBag.CompID   = compID;

            return(View(sortedClubTable));
        }
示例#5
0
        // GET: USER ScoreCard PENDING
        public ActionResult PendingScoreCards(int userID, int compID)
        {
            //Check User is in this Competition
            CompInfo cInfo    = new CompInfo();
            Boolean  IsInComp = cInfo.IsUserinComp(compID, userID);

            if (IsInComp == false)
            {
                TempData["FailUpload"]    = "You need to be in a competition to view your pending score cards ..";
                TempData["SuccessUpload"] = null;

                return(RedirectToAction("Index", "PLayerCompList"));
            }

            var pendingscoreCards = from sc in db.ScoreCardImages
                                    join ur in db.Users on sc.UserID equals ur.UserID
                                    join cr in db.CourseMains on sc.CourseID equals cr.CourseID
                                    where sc.Processed == false && sc.UserID == userID
                                    orderby sc.RoundDate
                                    select new ScoreCardView
            {
                playerName = ur.UserName,
                courseName = cr.ClubName,
                teeColour  = sc.TeeColour,
                SSS        = sc.SSS,
                rndDate    = sc.RoundDate,
                Note       = sc.Note,
                cardImage  = sc.CardImage,
                UserID     = sc.UserID,
                CourseID   = sc.CourseID,
                ImageID    = sc.ImageID
            };

            // Get Competition Name, Player Name, Current Handicap and Player Photo
            PlayerStats pStats      = new PlayerStats();
            var         compPlayers = from cp in db.CompPlayers
                                      where cp.UserID == userID && cp.CompID == compID
                                      select cp;

            int compPlayerID = 0;

            foreach (var item in compPlayers)
            {
                compPlayerID = item.CompPlayerID;
            }

            CompMain cMain = db.CompMains.Find(compID);

            ViewBag.PlayerName  = pStats.GetPlayerName(compPlayerID);
            ViewBag.PlayerPhoto = pStats.GetPlayerPhoto(compPlayerID);
            ViewBag.CurrentHCap = pStats.CurrentHcap(compPlayerID);
            ViewBag.CompName    = cMain.CompName;

            return(View(pendingscoreCards));
        }
示例#6
0
        public ActionResult Create([Bind(Include = "CompID,CompName,DateStart,DateEnd,Format")] CompMain compMain)
        {
            if (ModelState.IsValid)
            {
                DateTime CompStartDate = Convert.ToDateTime(compMain.DateStart);
                compMain.LeaguePosUpdate = CompStartDate.AddDays(7);
                db.CompMains.Add(compMain);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(compMain));
        }
示例#7
0
        // GET: Scores/Create
        public ActionResult Create(int compID, int userID, int courseID, string teeColour, int SSS, DateTime rndDate, string scorecardImage, int imageID)
        {
            // Set default Values for the CompScore model initial view
            var scoresModel = new CompScore();

            // Get compPlayerID
            var pStats       = new PlayerStats();
            int compPlayerID = pStats.GetcompPlayerID(userID, compID);

            // Populate the ScoresModel
            scoresModel.CompID       = compID;
            scoresModel.CourseID     = courseID;
            scoresModel.CompPlayerID = compPlayerID;
            scoresModel.TeeColour    = teeColour;
            scoresModel.SSS          = SSS;
            scoresModel.ImageID      = imageID;

            ViewBag.RndDate   = rndDate;
            ViewBag.cardImage = scorecardImage;

            // Get Competition Name
            CompMain compMain = db.CompMains.Find(compID);

            ViewBag.CompName = compMain.CompName;
            ViewBag.CompID   = compID;

            // Get Player Name
            CompPlayer compPlayer = db.CompPlayers.Find(compPlayerID);
            User       users      = db.Users.Find(userID);

            ViewBag.PlayerName = users.UserName;

            // Get Players Current Handicap
            ViewBag.Hcap  = pStats.CurrentHcap(compPlayerID);
            ViewBag.PHcap = Math.Round(ViewBag.HCap, MidpointRounding.AwayFromZero);

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

            ViewBag.CourseList = courseInfo.GetCourseList();

            // Populate variable to Tee Colour ddl
            ViewBag.TeeColourList = new SelectList(new[]
            {
                new { ID = "White", Name = "White" },
                new{ ID = "Yellow", Name = "Yellow" },
                new{ ID = "Red", Name = "Red" },
            }, "ID", "Name");

            return(View(scoresModel));
        }
示例#8
0
        // GET: CompMains/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CompMain compMain = db.CompMains.Find(id);

            if (compMain == null)
            {
                return(HttpNotFound());
            }
            return(View(compMain));
        }
示例#9
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());
        }
示例#10
0
        // GET: UpcomingRnds
        public ActionResult Index(int compPlayerID, int compID)
        {
            //Check User is in this Competition
            CompInfo compInfo = new CompInfo();
            int      userID   = Convert.ToInt32(Session["userid"]);
            Boolean  IsInComp = compInfo.IsUserinComp(compID, userID);

            if (IsInComp == false)
            {
                TempData["FailUpload"]    = "You need to be in a competition to register an upcoming round ..";
                TempData["SuccessUpload"] = null;

                return(RedirectToAction("Index", "PLayerCompList"));
            }

            // Get Players Upcoming Rounds
            CourseInfo cInfo = new CourseInfo();
            var        Rnds  = from rd in db.UpcomingRnds
                               where rd.CompPlayerID == compPlayerID && rd.CompID == compID
                               orderby rd.RndDate
                               select rd;

            foreach (var item in Rnds)
            {
                item.CourseName = cInfo.GetCourseName(item.CourseID);
            }

            // Get Competition Name, Player Name, Current Handicap and Player Photo
            PlayerStats pStats = new PlayerStats();

            CompMain cMain = db.CompMains.Find(compID);

            ViewBag.PlayerName   = pStats.GetPlayerName(compPlayerID);
            ViewBag.PlayerPhoto  = pStats.GetPlayerPhoto(compPlayerID);
            ViewBag.CurrentHCap  = pStats.CurrentHcap(compPlayerID);
            ViewBag.CompName     = cMain.CompName;
            ViewBag.CompPlayerID = compPlayerID;
            ViewBag.CompID       = compID;

            return(View(Rnds.ToList()));
        }
示例#11
0
        // GET: Scores
        public ActionResult ClubPlayerRnds(int compID, int courseID)
        {
            CompMain cMain = db.CompMains.Find(compID);

            var playerRnds = (from cs in db.CompScores
                              join cp in db.CompPlayers on cs.CompPlayerID equals cp.CompPlayerID
                              join pr in db.Profiles on cp.UserID equals pr.UserID
                              join ur in db.Users on pr.UserID equals ur.UserID
                              where cs.CompID == compID && cs.CourseID == courseID && pr.HomeClubID == courseID
                              orderby cs.RndDate
                              select new RndSummary
            {
                CompScoreID = cs.CompScoreID,
                RndDate = cs.RndDate,
                TeeColour = cs.TeeColour,
                RndPoints = cs.TotalPoints,
                SSS = cs.SSS,
                Handicap = cs.PlayerHcap,
                Player = ur.UserName
            }).ToList();

            // Get and store the Total Gross Score and Net Points for each round
            foreach (var item in playerRnds)
            {
                item.NETRndPoints = Convert.ToInt32(item.RndPoints - (cInfo.GetCoursePar(courseID, item.TeeColour) - item.SSS));
                item.RndScore     = rndSum.GetRndScore(item.CompScoreID);
            }

            // Sort Club Player Rounds into NET Points Order
            var sortedRnds = from sr in playerRnds
                             orderby sr.NETRndPoints descending
                             select sr;

            // Get Competition Name, Player Name, Current Handicap and Player Photo
            ViewBag.CompName = cMain.CompName;
            ViewBag.CompID   = cMain.CompID;
            ViewBag.ClubName = cInfo.GetCourseName(courseID);

            ViewBag.RndSummary = sortedRnds;
            return(View());
        }
示例#12
0
        public ActionResult DeleteComp(int compID)
        {
            CompInfo compInfo = new CompInfo();
            // Remove Each Player from this Competition
            var AllPlayers = from ap in db.CompPlayers
                             where ap.CompID == compID
                             select ap;

            foreach (var player in AllPlayers)
            {
                int compPlayerID = player.CompPlayerID;
                compInfo.RemovePlayer(compPlayerID);
            }

            // Remove the Main Competition Record
            CompMain compMain = db.CompMains.Find(compID);

            db.CompMains.Remove(compMain);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
示例#13
0
        // GET: UpcomingRnds/Create
        public ActionResult Create(int compPlayerID, int compID)
        {
            // Get Competition Name, Player Name, Current Handicap and Player Photo
            PlayerStats pStats = new PlayerStats();
            CompMain    cMain  = db.CompMains.Find(compID);

            ViewBag.PlayerName  = pStats.GetPlayerName(compPlayerID);
            ViewBag.PlayerPhoto = pStats.GetPlayerPhoto(compPlayerID);
            ViewBag.CurrentHCap = pStats.CurrentHcap(compPlayerID);
            ViewBag.CompName    = cMain.CompName;

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

            ViewBag.CourseList = courseInfo.GetCourseList();

            // default players home course
            var upcomingRnd = new UpcomingRnd();

            upcomingRnd.CourseID     = pStats.HomeClubID(compPlayerID);
            upcomingRnd.CompPlayerID = compPlayerID;


            // Options for Round Type - Competition or Practice
            List <SelectListItem> rndType = new List <SelectListItem>();

            rndType.Add(new SelectListItem()
            {
                Text = "Competiton", Value = "Competition"
            });
            rndType.Add(new SelectListItem()
            {
                Text = "Practice", Value = "Practice"
            });
            ViewBag.RndType = rndType;

            return(View(upcomingRnd));
        }
示例#14
0
        // GET: UpcomingRnds/Edit/5
        public ActionResult Edit(int?RndID)
        {
            if (RndID == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            UpcomingRnd upcomingRnd = db.UpcomingRnds.Find(RndID);

            // Get Competition Name, Player Name, Current Handicap and Player Photo
            PlayerStats pStats = new PlayerStats();
            CompMain    cMain  = db.CompMains.Find(upcomingRnd.CompID);

            ViewBag.PlayerName  = pStats.GetPlayerName(upcomingRnd.CompPlayerID);
            ViewBag.PlayerPhoto = pStats.GetPlayerPhoto(upcomingRnd.CompPlayerID);
            ViewBag.CurrentHCap = pStats.CurrentHcap(upcomingRnd.CompPlayerID);
            ViewBag.CompName    = cMain.CompName;

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

            ViewBag.CourseList = courseInfo.GetCourseList();

            // Options for Round Type - Competition or Practice
            List <SelectListItem> rndType = new List <SelectListItem>();

            rndType.Add(new SelectListItem()
            {
                Text = "Competiton", Value = "Competition"
            });
            rndType.Add(new SelectListItem()
            {
                Text = "Practice", Value = "Practice"
            });
            ViewBag.RndType = rndType;

            return(View(upcomingRnd));
        }
示例#15
0
        // GET: Players
        public ActionResult Index(int?CompID)
        {
            CompMain competition = db.CompMains.Find(CompID);

            if (competition == null)
            {
                return(HttpNotFound());
            }
            // Competition Name & CompID
            ViewBag.CompName = competition.CompName;
            ViewBag.CompID   = competition.CompID;

            var pStats = new PlayerStats();

            // List of Players NOT already in this Competition to show in check box list when adding players.
            var playerList = (from pl in db.Users
                              orderby pl.UserName
                              select pl).ToList();

            for (int i = playerList.Count - 1; i > -1; i--)
            {
                if (pStats.PlayerInComp(playerList[i].UserID, Convert.ToInt32(CompID)))
                {
                    playerList.RemoveAt(i);
                }
            }
            ViewBag.PlayerList = playerList;


            // Get Player Info for this competition and populate the PlayerView Model
            var getPlayers = (from cp in db.CompPlayers
                              join ur in db.Users on cp.UserID equals ur.UserID
                              where cp.CompID == CompID
                              select new PlayerView
            {
                playerName = ur.UserName,
                compPlayerID = cp.CompPlayerID
            }).ToList();

            // Loop through each Player and get their Number of Rounds Played, Gross Points, NET Points and average Points per Round
            for (int i = 0; i < getPlayers.Count(); i++)
            {
                getPlayers[i].rndsPlayed      = pStats.NumberRndsPlayed(Convert.ToInt32(CompID), getPlayers[i].compPlayerID);
                getPlayers[i].totalPoints     = pStats.TotalNumberPoints(Convert.ToInt32(CompID), getPlayers[i].compPlayerID);
                getPlayers[i].totalNETPoints  = pStats.TotalNETPoints(Convert.ToInt32(CompID), getPlayers[i].compPlayerID);
                getPlayers[i].avgPointsPerRnd = 0;
                if (getPlayers[i].rndsPlayed > 0)
                {
                    int rnds = getPlayers[i].rndsPlayed;
                    if (getPlayers[i].rndsPlayed > 10)
                    {
                        rnds = 10;
                    }
                    getPlayers[i].avgPointsPerRnd = Math.Round((Double)getPlayers[i].totalNETPoints / rnds, 2);
                }
            }
            ;

            // Sort list into Points Descending and apply current Position
            var sortedPlayers = (from sp in getPlayers
                                 orderby sp.avgPointsPerRnd descending, sp.playerName
                                 select sp).ToList();

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

                // Calc Positional Movement Current Position - Saved Current Position
                int savedPos = pStats.GetCurrentPosition(sortedPlayers[i].compPlayerID);
                if (savedPos > 0)
                {
                    int posMovement = savedPos - (i + 1);
                    sortedPlayers[i].posMove = posMovement;

                    if (posMovement > 0)
                    {
                        sortedPlayers[i].movementIcon = posUp;
                        pStats.SaveMovementIcon(sortedPlayers[i].compPlayerID, posUp);
                    }
                    else if (posMovement < 0)
                    {
                        sortedPlayers[i].movementIcon = posDown;
                        pStats.SaveMovementIcon(sortedPlayers[i].compPlayerID, posDown);
                    }
                    else
                    {
                        sortedPlayers[i].movementIcon = pStats.GetMovementIcon(sortedPlayers[i].compPlayerID);
                    }
                }

                //Update Current Player Position in Comp Player Table
                pStats.SaveCurrentPos(sortedPlayers[i].compPlayerID, i + 1);
            }

            return(View(sortedPlayers));
        }
示例#16
0
        public ActionResult PlayerScoreCard(int?compScoreID, int rndNumber)
        {
            ScoreInfo scoreInfo = new ScoreInfo();

            if (compScoreID == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CompScore compScore = db.CompScores.Find(compScoreID);

            int NumberofRnds = pStats.NumberRndsPlayed(Convert.ToInt32(compScore.CompID), compScore.CompPlayerID);

            if (NumberofRnds < rndNumber)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            // Get Course Logo using a stored procedure
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnValue("TigerLineScoresDB")))
            {
                List <String> courseLogo = connection.Query <string>("dbo.spGetLogoImagePath @CourseID", new { CourseID = compScore.CourseID }).ToList();
                ViewBag.CourseLogo = courseLogo[0];
            }

            ViewBag.PHcap        = compScore.PlayerHcap;
            ViewBag.PlayerName   = pStats.GetPlayerName(compScore.CompPlayerID);
            ViewBag.PlayerPhoto  = pStats.GetPlayerPhoto(compScore.CompPlayerID);
            ViewBag.PlayerHomeID = pStats.HomeClubID(compScore.CompPlayerID);
            ViewBag.RndDate      = compScore.RndDate;
            ViewBag.RndNumber    = rndNumber;

            // Score Card Image
            ViewBag.CardImage = compInfo.GetScoreCardImage(compScore.CompScoreID);

            CourseMain courseM = db.CourseMains.Find(compScore.CourseID);

            ViewBag.CourseName = courseM.ClubName;

            CompMain cMain = db.CompMains.Find(compScore.CompID);

            ViewBag.CompName = cMain.CompName;

            // Get the Course Par
            ViewBag.CoursePar = cInfo.GetCoursePar(compScore.CourseID, compScore.TeeColour);

            // Get the NET Points (Gross Points - (CoursePar - SSS))
            ViewBag.NetPoints = compScore.TotalPoints - (ViewBag.CoursePar - compScore.SSS);

            if (compScore == null)
            {
                return(HttpNotFound());
            }

            // Get Course Details depending on course and tee colour selected
            int     courseID  = compScore.CourseID;
            string  teeColour = compScore.TeeColour;
            decimal?PHcap     = compScore.PlayerHcap;

            ViewBag.scoreCard = cInfo.GetCourseDetails(Convert.ToInt32(courseID), teeColour);

            // Get Hole Scores
            ViewBag.CurrentScore = compScore;
            // Front 9 Total Score
            ViewBag.FrontScore = scoreInfo.FrontScore(compScore.CompScoreID);
            // Back 9 Total Score
            ViewBag.BackScore = scoreInfo.BackScore(compScore.CompScoreID);
            // Total Score
            ViewBag.TotalScore = ViewBag.FrontScore + ViewBag.BackScore;

            // Blank Points
            CompPoints compPoints = pScore.GetCompPoints(compScore);

            ViewBag.RndPoints = compPoints;

            // Get Course Totals depending on course and tee colour - Store totals in View bag variables
            CourseTotals cTotals = cInfo.GetCourseTotals(Convert.ToInt32(courseID), teeColour);

            ViewBag.TeeColour = cTotals.teeColour;
            ViewBag.FrontYrds = cTotals.frontYrds;
            ViewBag.BackYrds  = cTotals.backYrds;
            ViewBag.TotalYrds = cTotals.totalYrds;
            ViewBag.FrontPar  = cTotals.frontPar;
            ViewBag.BackPar   = cTotals.backPar;
            ViewBag.TotalPar  = cTotals.totalPar;

            // Store the playing handicap in the ViewBag
            var playingHCap = 0;

            if (PHcap != null)
            {
                playingHCap = Convert.ToInt32(PHcap);
            }
            ViewBag.PHcap = playingHCap;

            return(PartialView("_ScoreCard", compScore));
        }
示例#17
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());
        }
示例#18
0
        // GET: List of Players
        public ActionResult LeagueTable(int compID)
        {
            CompMain competition = db.CompMains.Find(compID);

            if (competition == null)
            {
                return(HttpNotFound());
            }
            // Competition Name & CompID
            ViewBag.CompName = competition.CompName;
            ViewBag.CompID   = competition.CompID;

            var pStats = new PlayerStats();
            // Get Player Info for this competition and populate the PlayerView 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
                              select new PlayerView
            {
                playerName = ur.UserName,
                compPlayerID = cp.CompPlayerID,
                Photo = pr.Photo
            }).ToList();

            // Loop through each Player and get their Number of Rounds Played, Gross Points, NET Points and average Points per Round
            for (int i = 0; i < getPlayers.Count(); i++)
            {
                getPlayers[i].rndsPlayed      = pStats.NumberRndsPlayed(Convert.ToInt32(compID), getPlayers[i].compPlayerID);
                getPlayers[i].totalPoints     = pStats.TotalNumberPoints(Convert.ToInt32(compID), getPlayers[i].compPlayerID);
                getPlayers[i].totalNETPoints  = pStats.TotalNETPoints(Convert.ToInt32(compID), getPlayers[i].compPlayerID);
                getPlayers[i].avgPointsPerRnd = 0;
                if (getPlayers[i].rndsPlayed > 0)
                {
                    int rnds = getPlayers[i].rndsPlayed;
                    if (getPlayers[i].rndsPlayed > 10)
                    {
                        rnds = 10;
                    }

                    getPlayers[i].avgPointsPerRnd = Math.Round((Double)getPlayers[i].totalNETPoints / rnds, 2);
                }

                // Get current Movement Icon
                getPlayers[i].movementIcon = pStats.GetMovementIcon(getPlayers[i].compPlayerID);
            }
            ;

            // Sort list into Points Descending and apply current Position

            var sortedPlayers = (from sp in getPlayers
                                 orderby sp.avgPointsPerRnd descending, sp.playerName
                                 select sp).ToList();

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

            // See if the weekly league position movement needs to be carried out
            if (DateTime.Now.Date > competition.LeaguePosUpdate)
            {
                // Calculate Week league position movement for each Player
                for (int i = 0; i < sortedPlayers.Count(); i++)
                {
                    int        compPlayerID    = sortedPlayers[i].compPlayerID;
                    CompPlayer cPlayer         = db.CompPlayers.Find(compPlayerID);
                    int        CurrentPos      = sortedPlayers[i].currentPosition;
                    int        SavedWeekPos    = CurrentPos;
                    string     updatedMoveIcon = "";
                    if (cPlayer.WeekPos != null)
                    {
                        SavedWeekPos = Convert.ToInt32(cPlayer.WeekPos);
                    }
                    int posMovement = SavedWeekPos - CurrentPos;
                    sortedPlayers[i].posMove = posMovement;

                    if (posMovement > 0)
                    {
                        sortedPlayers[i].movementIcon = posUp;
                        updatedMoveIcon = posUp;
                    }
                    else if (posMovement < 0)
                    {
                        sortedPlayers[i].movementIcon = posDown;
                        updatedMoveIcon = posDown;
                    }
                    else
                    {
                        sortedPlayers[i].movementIcon = posNomove;
                        updatedMoveIcon = posNomove;
                    }
                    cPlayer.WeekPos         = CurrentPos;
                    cPlayer.CurrentPos      = CurrentPos;
                    cPlayer.MovementIcon    = updatedMoveIcon;
                    db.Entry(cPlayer).State = EntityState.Modified;
                }
                // Update the compMain record with new League Postion Update date + 7 Days from Now

                competition.LeaguePosUpdate = DateTime.Now.AddDays(7);
                db.Entry(competition).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(View(sortedPlayers));
        }