Ejemplo n.º 1
0
        protected void GetGame()
        {
            // populate the form with existing department data from the db
            int GameID = Convert.ToInt32(Request.QueryString["gameID"]);

            // connect to the EF DB
            using (GameConnection db = new GameConnection())
            {
                // populate a department instance with the departmentID from the URL parameter
                game updatedGame = (from Games in db.games
                                    where Games.gameID == GameID
                                    select Games).FirstOrDefault();

                // map the Department properties to the form controls
                if (updatedGame != null)
                {
                    teamA.Text = updatedGame.teamA;
                    teamB.Text = updatedGame.teamB;
                    teamAScore.Text = updatedGame.teamAScore.ToString();
                    teamBScore.Text = updatedGame.teamBScore.ToString();

                }

            }
        }
Ejemplo n.º 2
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            using (GameConnection db = new GameConnection())
            {
                game newGame = new game();

                if (football.Checked == true)
                {
                    var game = "football";
                    newGame.teamA = teamA.Text;
                    newGame.teamB = teamB.Text;
                    newGame.teamAScore = Convert.ToInt32(teamAScore.Text);
                    newGame.teamBScore = Convert.ToInt32(teamBScore.Text);
                    newGame.selectedGame = game;
                    db.games.Add(newGame);
                    db.SaveChanges();

                }

                if (cricket.Checked == true)
                {
                    var game = "cricket";
                    newGame.teamA = teamA.Text;
                    newGame.teamB = teamB.Text;
                    newGame.teamAScore = Convert.ToInt32(teamAScore.Text);
                    newGame.teamBScore = Convert.ToInt32(teamBScore.Text);
                    newGame.selectedGame = game;
                    db.games.Add(newGame);
                    db.SaveChanges();

                }

                if (hockey.Checked == true)
                {
                    var game = "hockey";
                    newGame.teamA = teamA.Text;
                    newGame.teamB = teamB.Text;
                    newGame.teamAScore = Convert.ToInt32(teamAScore.Text);
                    newGame.teamBScore = Convert.ToInt32(teamBScore.Text);
                    newGame.selectedGame = game;
                    db.games.Add(newGame);
                    db.SaveChanges();

                }
                Response.Redirect("~/Default.aspx");
            }
        }