Пример #1
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            // Use EF to connect to the server
            using (TeamConnection db = new TeamConnection())
            {
                // use the Student model to create a new student object and
                // save a new record
                team newTeam = new team();

                int TeamID = 0;

                if (Request.QueryString.Count > 0) // our URL has a StudentID in it
                {
                    // get the id from the URL
                    TeamID = Convert.ToInt32(Request.QueryString["team_id"]);

                    // get the current student from EF DB
                    newTeam = (from teams in db.teams
                               where teams.team_id == TeamID
                               select teams).FirstOrDefault();
                }

                // add form data to the new student record
                newTeam.team_wins            = Convert.ToInt32(WinsTextBox.Text);
                newTeam.team_losses          = Convert.ToInt32(LossesTextBox.Text);
                newTeam.team_rank            = Convert.ToInt32(RankTextBox.Text);
                newTeam.team_number_of_games = Convert.ToInt32(NumberofGamesTextBox.Text);

                // use LINQ to ADO.NET to add / insert new student into the database

                if (TeamID == 0)
                {
                    db.teams.Add(newTeam);
                }


                // save our changes - also updates and inserts
                try {
                    db.SaveChanges();
                }
                catch (Exception err)
                {
                    Console.WriteLine(err);
                }

                // Redirect back to the updated students page
                Response.Redirect("~/Default.aspx");
            }
        }
        /**
         * @description Event Handler for deleteing a game
         * @method GamesGridView_RowDeleting
         * @param {object} sender
         * @param {EventArgs} e
         * @return {void}
         */
        protected void GamesGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int selectedRow = e.RowIndex;

            int GameId = Convert.ToInt32(GamesGridView.DataKeys[selectedRow].Values["GameId"]);

            using (TeamConnection db = new TeamConnection())
            {
                Game deleteGame = (from game in db.Games
                                   where game.GameId == GameId
                                   select game).FirstOrDefault();
                db.Games.Remove(deleteGame);
                db.SaveChanges();
                this.GetGames();
            }
        }
Пример #3
0
        /**
         * @description Event Handler deleting a team from the database
         * @method TeamsGridView_RowDeleting
         * @param {object} sender
         * @param {EventArgs} e
         * @return {void}
         */
        protected void TeamsGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int selectedRow = e.RowIndex;

            int TeamId = Convert.ToInt32(TeamsGridView.DataKeys[selectedRow].Values["TeamId"]);

            using (TeamConnection db = new TeamConnection())
            {
                Team deleteTeam = (from team in db.Teams
                                   where team.TeamId == TeamId
                                   select team).FirstOrDefault();

                db.Teams.Remove(deleteTeam);
                db.SaveChanges();
                this.GetTeams();
            }
        }
Пример #4
0
        /**
         * @description Event Handler for save button press, saves the team into the database if all required fields are filed in
         * @method SaveButton_Click
         * @param {object} sender
         * @param {EventArgs} e
         * @return {void}
         */
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            //use EF to connect to the server
            using (TeamConnection db = new TeamConnection())
            {
                //use the Student model to create a new student object and
                //save a new record
                Game newGame = new Game();

                string home = HomeTeamDropDownList.Text;
                string away = AwayTeamDropDownList.Text;
                System.Diagnostics.Debug.WriteLine(HomeTeamDropDownList.Text);
                System.Diagnostics.Debug.WriteLine(home);
                System.Diagnostics.Debug.WriteLine(home.Equals("Balls & Dolls"));

                var homeTeamId = (from teams in db.Teams
                                  where teams.TeamName == home
                                  select teams).FirstOrDefault().TeamId;

                var awayTeamId = (from teams in db.Teams
                                  where teams.TeamName == away
                                  select teams).FirstOrDefault().TeamId;

                System.Diagnostics.Debug.WriteLine(homeTeamId); System.Diagnostics.Debug.WriteLine(homeTeamId); System.Diagnostics.Debug.WriteLine(homeTeamId); System.Diagnostics.Debug.WriteLine(homeTeamId);
                //add data to the new Game record
                newGame.HomeTeamId = Convert.ToInt32(homeTeamId);
                newGame.AwayTeamId = Convert.ToInt32(awayTeamId);
                newGame.HomePoints = Convert.ToInt32(HomePointsTextBox.Text);
                newGame.AwayPoints = Convert.ToInt32(AwayPointsTextBox.Text);
                newGame.Spectators = Convert.ToInt32(SpectatorsTextBox.Text);
                newGame.GameDate   = Convert.ToDateTime(GameDateTextBox.Text);

                //use LINQ to ADO.net to add / insert my new Game into the DB
                db.Games.Add(newGame);

                //save our changes
                db.SaveChanges();

                //redirect back to the updated Games page
                Response.Redirect("~/DodgeBall/Games.aspx");
            }
        }
        /**
         * @description Event Handler for save button click
         * @method SaveButton_Click
         * @param {object} sender
         * @param {EventArgs} e
         * @return {void}
         */
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            //connect to the server
            using (TeamConnection db = new TeamConnection())
            {
                Team newTeam = new Team();

                int teamID = 0;

                if (Request.QueryString.Count > 0)
                {
                    teamID = Convert.ToInt32(Request.QueryString["teamID"]);

                    newTeam = (from team in db.Teams
                               where team.TeamId == teamID
                               select team).FirstOrDefault();
                }

                //add data to the new student record
                newTeam.TeamName = TeamNameTextBox.Text;



                if (teamID == 0)
                {
                    //use LINQ and ADO.NET to add or insert newStudent into the Database
                    db.Teams.Add(newTeam);
                }


                //save changes
                db.SaveChanges();

                //redirect back to the updated students page
                Response.Redirect("~/DodgeBall/Teams.aspx");
            }
        }