protected void ButtonStartContest_Click(object sender, EventArgs e)
        {
            //Redirect to contest start page.
            if (Session["pgEditContestPlayers.m_nContestId"] != null)
            {
                m_nContestId = Convert.ToInt32(Session["pgEditContestPlayers.m_nContestId"]);
            }

            using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
            {
                int m_nNumberOfPlayers = context.TableHockeyContestPlayer.Where(c => (c.PlayerId != -1) && (c.ContestId == m_nContestId)).Count();
                //If odd number of players, add extra dummy player (if none exists, shouldn't happen). This is a temporary fix that may be altered in the future. 120507.
                if (PageUtility.isOdd(m_nNumberOfPlayers))
                {
                    TableHockeyContestPlayer m_existingDummyPlayer = context.TableHockeyContestPlayer.FirstOrDefault(c => (c.PlayerId == -1) && (c.ContestId == m_nContestId));
                    if (m_existingDummyPlayer == null)
                    {
                        TableHockeyContestPlayer m_dummyPlayer = new TableHockeyContestPlayer();
                        m_dummyPlayer.ContestId            = m_nContestId;
                        m_dummyPlayer.PlayerId             = -1;
                        m_dummyPlayer.isDummyContestPlayer = true;
                        context.TableHockeyContestPlayer.Add(m_dummyPlayer);
                    }
                    context.SaveChanges();
                }
            }

            Response.Redirect("~/pgEditContestTable.aspx?ContestId=" + m_nContestId);
        }
        protected void ButtonAddSelectedPlayersToContest_Click(object sender, EventArgs e)
        {
            Dictionary <int, int> m_selectedPlayerIDs = GetCheckedPlayerIndexes(GridViewAvailablePlayers, "checkSelectPlayer");

            if (Session["pgEditContestPlayers.m_nContestId"] != null)
            {
                m_nContestId = Convert.ToInt32(Session["pgEditContestPlayers.m_nContestId"]);
            }
            using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
            {
                foreach (int m_nPlayerId in m_selectedPlayerIDs.Values)
                {
                    TableHockeyContestPlayer m_contestPlayer = new TableHockeyContestPlayer();
                    m_contestPlayer.ContestId            = m_nContestId;
                    m_contestPlayer.PlayerId             = m_nPlayerId;
                    m_contestPlayer.isDummyContestPlayer = false;
                    context.TableHockeyContestPlayer.Add(m_contestPlayer);
                }
                context.SaveChanges();
            }

            if (m_selectedPlayerIDs.Count > 0)
            {
                populateAvailablePlayers(m_nContestId);
                populateSelectedPlayers(m_nContestId);
            }
        }
        protected void ButtonRemoveSelectedPlayersFromContest_Click(object sender, EventArgs e)
        {
            Dictionary <int, int> m_selectedPlayerIDs = GetCheckedPlayerIndexes(GridViewSelectedPlayers, "checkSelectPlayer");

            if (Session["pgEditContestPlayers.m_nContestId"] != null)
            {
                m_nContestId = Convert.ToInt32(Session["pgEditContestPlayers.m_nContestId"]);
            }
            using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
            {
                foreach (int m_nPlayerId in m_selectedPlayerIDs.Values)
                {
                    if (isPlayerOKToRemoveFromContest(m_nPlayerId, m_nContestId))
                    {
                        TableHockeyContestPlayer m_contestPlayer = context.TableHockeyContestPlayer.First(c => (c.PlayerId == m_nPlayerId) && (c.ContestId == m_nContestId));
                        context.TableHockeyContestPlayer.Remove(m_contestPlayer);
                    }
                }
                context.SaveChanges();
            }
            if (m_selectedPlayerIDs.Count > 0)
            {
                populateAvailablePlayers(m_nContestId);
                populateSelectedPlayers(m_nContestId);
            }
        }
Ejemplo n.º 4
0
        protected void ButtonEndGame_Click(object sender, EventArgs e)
        {
            int m_nNumberOfRounds = -1;

            if (!int.TryParse(TextBoxEndGameRounds.Text.Trim(), out m_nNumberOfRounds))
            {
                this.cvEndGameRounds.IsValid = false;
                return;
            }

            this.cvEndGameRounds.IsValid = true;
            //Get selected players for end game.
            Dictionary <int, int> m_selectedPlayerIDs = this.ucContestTable1.CheckedPlayersToEndGame;

            if ((m_selectedPlayerIDs != null) && (m_selectedPlayerIDs.Count > 1))
            {
                this.cvEndGamePlayers.IsValid = true;
                if (m_currentContest == null)
                {
                    m_currentContest = (TableHockeyContest)Session["pgEditContestTable.m_currentContest"];
                }

                //Create new end game contest for current contest.
                TableHockeyContestHandler m_handler           = new TableHockeyContestHandler();
                TableHockeyContest        m_newEndGameContest = m_handler.createDefaultEndGameTableHockeyContest(m_currentContest);
                m_newEndGameContest.numberOfRounds = Convert.ToInt32(TextBoxEndGameRounds.Text);
                //Add selected players to end game contest.  Make sure to export final table standing for each player.
                int m_nEndGameContestId = -1;
                using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
                {
                    //Create new end game only if no previous exists.
                    var queryExistingEndGame = context.TableHockeyContest.FirstOrDefault(c => c.EndGameForContestId == m_nContestId);
                    if (queryExistingEndGame == null)
                    {
                        context.TableHockeyContest.Add(m_newEndGameContest);
                        context.SaveChanges();
                    }
                }

                using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
                {
                    //Add new players to end game if none exist.

                    var queryExistingEndGame = context.TableHockeyContest.FirstOrDefault(c => c.EndGameForContestId == m_nContestId);
                    if (queryExistingEndGame != null)
                    {
                        m_nEndGameContestId = queryExistingEndGame.ContestId;
                        var queryExistingPlayers = context.TableHockeyContestPlayer.FirstOrDefault(p => p.ContestId == m_nEndGameContestId);
                        //Only add players if none exist.
                        if (queryExistingPlayers == null)
                        {
                            foreach (KeyValuePair <int, int> kvp in m_selectedPlayerIDs)
                            {
                                TableHockeyContestPlayer m_contestPlayer = new TableHockeyContestPlayer();
                                m_contestPlayer.ContestId             = m_nEndGameContestId;
                                m_contestPlayer.PlayerId              = kvp.Value;
                                m_contestPlayer.FinalPreviousStanding = 1 + kvp.Key;
                                m_contestPlayer.isDummyContestPlayer  = false;
                                context.TableHockeyContestPlayer.Add(m_contestPlayer);
                            }
                            context.SaveChanges();
                        }
                    }
                }
                using (var context = new TableHockeyData.UHSSWEB_DEVEntities())
                {
                    //Create new end game only if no previous exists.
                    var queryExistingEndGame = context.TableHockeyContest.FirstOrDefault(c => c.EndGameForContestId == m_nContestId);
                    if (queryExistingEndGame != null)
                    {
                        TableHockeyContest m_endGame = (TableHockeyContest)queryExistingEndGame;
                        m_nEndGameContestId = m_endGame.ContestId;
                    }
                }
                Response.Redirect("~/pgEditContestTableEndGame.aspx?ContestId=" + m_nEndGameContestId);
            }
            else
            {
                this.cvEndGamePlayers.IsValid = false;
            }
        }