protected void GamesGridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { // store which row was clicked int selectedRow = e.RowIndex; // get the selected GamesID using the Grid's DataKey Collection int gameID = Convert.ToInt32(GamesGridView.DataKeys[selectedRow].Values["GameID"]); // use EF to find the selected Game from DB and remove it using (GameTrackerConnection db = new GameTrackerConnection()) { Game deletedGame = (from gameRecords in db.Games where gameRecords.GameID == gameID select gameRecords).FirstOrDefault(); //// perform the removal for the two teams in db for (int i = 0; i < 2; i++) { Team deletedTeam = (from teamRecords in db.Teams where teamRecords.GameID == gameID select teamRecords).FirstOrDefault(); db.Teams.Remove(deletedTeam); db.SaveChanges(); } // perform complete removal in the DB db.Games.Remove(deletedGame); db.SaveChanges(); // refresh the grid this.GetGames(); } }
/** * <summary> * This event handler deletes a game from the databse using EF * </summary> * @method GamesGridView_RowDeleting * @param {object} sender * @param {GridViewDeleteEventArgs} * @returns {void} * */ protected void GamesGridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { //store which row was clicked int selectedRow = e.RowIndex; //get the selected gamename using the grids datakey collection int GameID = Convert.ToInt32(GamesGridView.DataKeys[selectedRow].Values["GameID"]); //use ef to find the slected game and delete it using (GameTrackerConnection db = new GameTrackerConnection()) { //create object of the game class and store the query string inside of it Game deletedGame = (from gameRecords in db.Games where gameRecords.GameID == GameID select gameRecords).FirstOrDefault(); //remove the selected game from the db db.Games.Remove(deletedGame); //save db changes db.SaveChanges(); //refresh gridview this.GetGames(); } }
/** * <summary> * This method deletes record from the DB * </summary> * @method CsgoGridView_RowDeleting * @returns {VOID} * */ protected void CsgoGridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { int selectedRow = e.RowIndex; // store which row was called int gameID = Convert.ToInt32(CsgoGridView.DataKeys[selectedRow].Values["gameID"]); // get game ID if (HttpContext.Current.User.Identity.IsAuthenticated) // check to see if user is logged in { //connect to db to remove row using (GameTrackerConnection db = new GameTrackerConnection()) { Csgo removedGame = (from gameRecords in db.Csgoes where gameRecords.gameID == gameID select gameRecords).FirstOrDefault(); db.Csgoes.Remove(removedGame); db.SaveChanges(); this.GetCsgoData(); } } else { Response.Redirect("~/Login.aspx"); } }
/** * <summary> * This event handler deletes a team from the database using EF * </summary> * @method TeamsGridView_RowDeleting * @param {object} sender * @param {GridViewDeleteEventArgs} * @returns {void} * */ protected void TeamsGridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { //store which row was clicked int selectedRow = e.RowIndex; //get the selected teamID using the grids datakey collection int TeamID = Convert.ToInt32(TeamsGridView.DataKeys[selectedRow].Values["TeamID"]); //use ef to find the selected team and delete it using (GameTrackerConnection db = new GameTrackerConnection()) { //create object of the team class and store the query int inside of it Team deletedTeam = (from teamRecords in db.Teams where teamRecords.TeamID == TeamID select teamRecords).FirstOrDefault(); //remove the selected team from the db db.Teams.Remove(deletedTeam); //save db changes db.SaveChanges(); //refresh gridview this.GetTeams(); } }
/** * <summary> * This method creates a new team object and adds it to the database, redirects the user to team viewing page * </summary> * @method SaveButton_Click * @return {void} * */ protected void SaveButton_Click(object sender, EventArgs e) { // Use EF to connect to the server using (GameTrackerConnection db = new GameTrackerConnection()) { // use the Teams model to create a new team object and save a new record Team newTeam = new Team(); int TeamID = 0; // add form data to the new teams record newTeam.TeamName = TeamNameTextBox.Text; newTeam.Description = DescriptionTextBox.Text; newTeam.Sport = SportTextBox.Text; newTeam.City = CityTextBox.Text; newTeam.TotalRuns = Convert.ToInt32(TotalRunsTextBox.Text); newTeam.AllowedRuns = Convert.ToInt32(AllowedRunsTextBox.Text); // use LINQ to ADO.NET to add / insert new team into the database if (TeamID == 0) { db.Teams.Add(newTeam); } // save our changes - also updates and inserts db.SaveChanges(); // Redirect back to the updated departments page Response.Redirect("~/Team.aspx"); } }
/** * <summary> * This method creates a game object based on that information, then redirects the user back to the home page. * </summary> * @method SaveButton_Click * @return {void} * */ protected void SaveButton_Click(object sender, EventArgs e) { // Use EF to connect to the server using (GameTrackerConnection db = new GameTrackerConnection()) { // use the Games model to create a new Game object and save a new record Game newGame = new Game(); int GameID = 0; // add form data to the new games record newGame.GameName = GameNameTextBox.Text; newGame.Description = DescriptionTextBox.Text; newGame.Runs = Convert.ToInt32(RunsTextBox.Text); newGame.Spectators = Convert.ToInt32(SpectatorsTextBox.Text); newGame.Team1 = Team1DropDownList.SelectedValue; newGame.Team2 = Team2DropDownList.SelectedValue; newGame.WinningTeam = WinningTeamTextBox.Text; newGame.Created = DateTime.Now.Date; // use LINQ to ADO.NET to add / insert new game into the database if (GameID == 0) { db.Games.Add(newGame); } // save our changes - also updates and inserts db.SaveChanges(); // Redirect back to the updated games page Response.Redirect("~/Default.aspx"); } }
/** * <summary> * This method takes all the inputs on the csgo details page and inserts it to the fields in the table * </summary> * @method SaveButton_Click * @returns {void} * */ protected void SaveButton_Click(object sender, EventArgs e) { using (GameTrackerConnection db = new GameTrackerConnection()) { //creating new csgo object based on the model Csgo csgoGameDetails = new Csgo(); int gameID = 0; if (Request.QueryString.Count > 0)// our url has a gameID in it { gameID = Convert.ToInt32(Request.QueryString["gameID"]); //get the current game from EF DB csgoGameDetails = (from csgo in db.Csgoes where csgo.gameID == gameID select csgo).FirstOrDefault(); } string week = weekNumber.Text; string[] weekArray = null; char[] splitChar = { 'W' }; weekArray = week.Split(splitChar); string weekNum = weekArray[1]; //add form data to the new game record csgoGameDetails.team1 = Team1TextBox.Text; csgoGameDetails.team2 = Team2TextBox.Text; csgoGameDetails.roundsWon = int.Parse(RoundsForTeam1TextBox.Text); csgoGameDetails.roundsWonTeam2 = int.Parse(RoundsForTeam2TextBox.Text); csgoGameDetails.totalPoints = int.Parse(PointsForTeam1TextBox.Text); csgoGameDetails.totalPointsTeam2 = int.Parse(PointsForTeam2TextBox.Text); csgoGameDetails.mapPlayed = MapPlayedTexBox.Text; csgoGameDetails.spectators = int.Parse(SpectatorsTextBox.Text); csgoGameDetails.winner = WinnerTextBox.Text; //csgoGameDetails.weekOfGame = int.Parse(WeekTextBox.Text); csgoGameDetails.weekOfGame = int.Parse(weekNum); //use LINQ to ADO.NET to insert record to DB if (gameID == 0) { db.Csgoes.Add(csgoGameDetails); } //save all changes in the DB db.SaveChanges(); //redirect to csgo stats page Response.Redirect("~/Csgo.aspx"); } }
/** * <summary> * This method takes all the inputs on the smite details page and inserts it to the fields in the table * </summary> * @method SaveButton_Click * @returns {void} * */ protected void SaveButton_Click(object sender, EventArgs e) { using (GameTrackerConnection db = new GameTrackerConnection()) { //creating new smite object based on the model Smite SmiteGameDetails = new Smite(); int gameID = 0; if (Request.QueryString.Count > 0)// our url has a gameID in it { gameID = Convert.ToInt32(Request.QueryString["gameID"]); //get the current game from EF DB SmiteGameDetails = (from smite in db.Smites where smite.gameID == gameID select smite).FirstOrDefault(); } string week = weekNumberSmite.Text; string[] weekArray = null; char[] splitChar = { 'W' }; weekArray = week.Split(splitChar); string weekNum = weekArray[1]; //add form data to the new game record SmiteGameDetails.team1 = Team1SmiteTextBox.Text; SmiteGameDetails.team2 = Team2SmiteTextBox.Text; SmiteGameDetails.killsTeam1 = int.Parse(KillsForTeam1TextBox.Text); SmiteGameDetails.killsTeam2 = int.Parse(KillsForTeam2TextBox.Text); SmiteGameDetails.pointsTeam1 = int.Parse(PointsSmiteForTeam1TextBox.Text); SmiteGameDetails.pointsTeam2 = int.Parse(PointsSmiteForTeam2TextBox.Text); SmiteGameDetails.spectators = int.Parse(SpectatorsSmiteTextBox.Text); SmiteGameDetails.winner = WinnerSmiteTextBox.Text; //csgoGameDetails.weekOfGame = int.Parse(WeekTextBox.Text); SmiteGameDetails.weekOfGame = int.Parse(weekNum); //use LINQ to ADO.NET to insert record to DB if (gameID == 0) { db.Smites.Add(SmiteGameDetails); } //save all changes in the DB db.SaveChanges(); //redirect to smite stats page Response.Redirect("~/Smite.aspx"); } }
/** * <summary> * This method takes all the inputs on the dota details page and inserts it to the fields in the table * </summary> * @method SaveButton_Click * @returns {void} * */ protected void SaveButton_Click(object sender, EventArgs e) { using (GameTrackerConnection db = new GameTrackerConnection()) { //creating new csgo object based on the model Dota dotaGameDetails = new Dota(); int gameID = 0; if (Request.QueryString.Count > 0)// our url has a gameID in it { gameID = Convert.ToInt32(Request.QueryString["gameID"]); //get the current game from EF DB dotaGameDetails = (from dota in db.Dotas where dota.gameID == gameID select dota).FirstOrDefault(); } string week = weekNumber.Text; string[] weekArray = null; char[] splitChar = { 'W' }; weekArray = week.Split(splitChar); string weekNum = weekArray[1]; //add form data to the new game record dotaGameDetails.team1 = Team1DotaTextBox.Text; dotaGameDetails.team2 = Team2DotaTextBox.Text; dotaGameDetails.killsTeam1 = int.Parse(KillsForTeam1TextBox.Text); dotaGameDetails.killsTeam2 = int.Parse(KillsForTeam2TextBox.Text); dotaGameDetails.objectivesTeam1 = int.Parse(ObjectivesForTeam1TextBox.Text); dotaGameDetails.objectivesTeam2 = int.Parse(ObjectivesForTeam2TextBox.Text); dotaGameDetails.spectators = int.Parse(SpectatorsDotaTextBox.Text); dotaGameDetails.winner = WinnerDotaTextBox.Text; dotaGameDetails.weekOfGame = int.Parse(weekNum); //use LINQ to ADO.NET to insert record to DB if (gameID == 0) { db.Dotas.Add(dotaGameDetails); } //save all changes in the DB db.SaveChanges(); //redirect to dota stats page Response.Redirect("~/Dota.aspx"); } }
/** * <summary> * This method creates a new team object and adds it to the database, redirects the user to team viewing page * </summary> * @method SaveButton_Click * @return {void} * */ protected void SaveButton_Click(object sender, EventArgs e) { // Use EF to connect to the server using (GameTrackerConnection db = new GameTrackerConnection()) { // use the Teams model to create a new team object and save a new record Team newTeam = new Team(); int TeamID = 0; if (Request.QueryString.Count > 0) // our URL has a Team in it { // get the id from the URL TeamID = Convert.ToInt32(Request.QueryString["TeamID"]); // get the current team from EF DB newTeam = (from team in db.Teams where team.TeamID == TeamID select team).FirstOrDefault(); } // add form data to the new teams record newTeam.TeamName = TeamNameTextBox.Text; newTeam.Description = DescriptionTextBox.Text; newTeam.Sport = SportTextBox.Text; newTeam.City = CityTextBox.Text; newTeam.TotalRuns = Convert.ToInt32(TotalRunsTextBox.Text); newTeam.AllowedRuns = Convert.ToInt32(AllowedRunsTextBox.Text); // use LINQ to ADO.NET to add / insert new team into the database if (TeamID == 0) { db.Teams.Add(newTeam); } // save our changes - also updates and inserts db.SaveChanges(); // Redirect back to the updated admin teams page Response.Redirect("~/Admin/AdminTeams.aspx"); } }
/** * <summary> * This method creates a game object based on that information, then redirects the user back to the admin games page. * </summary> * @method SaveButton_Click * @return {void} * */ protected void SaveButton_Click(object sender, EventArgs e) { // Use EF to connect to the server using (GameTrackerConnection db = new GameTrackerConnection()) { // use the Games model to create a new Game object and save a new record Game newGame = new Game(); int GameID = 0; if (Request.QueryString.Count > 0) // our URL has a GameID in it { // get the id from the URL GameID = Convert.ToInt32(Request.QueryString["GameID"]); // get the current game from EF DB newGame = (from game in db.Games where game.GameID == GameID select game).FirstOrDefault(); } // add form data to the new games record newGame.GameName = GameNameTextBox.Text; newGame.Description = DescriptionTextBox.Text; newGame.Runs = Convert.ToInt32(RunsTextBox.Text); newGame.Spectators = Convert.ToInt32(SpectatorsTextBox.Text); newGame.Team1 = Team1TextBox.Text; newGame.Team2 = Team2TextBox.Text; newGame.WinningTeam = WinningTeamTextBox.Text; newGame.Created = Convert.ToDateTime(CreatedDate.Text).Date; // use LINQ to ADO.NET to add / insert new game into the database if (GameID == 0) { db.Games.Add(newGame); } // save our changes - also updates and inserts db.SaveChanges(); // Redirect back to the updated games page Response.Redirect("~/Admin/AdminGames.aspx"); } }
protected void SaveButton_Click(object sender, EventArgs e) { if (CustomValidator1.IsValid) { //convert scores int Points1 = Convert.ToInt32(Team1PointsTextBox.Text), Points2 = Convert.ToInt32(Team2PointsTextBox.Text), PointsAllowed = Convert.ToInt32(PointsAllowedTextBox.Text); // Use EF to connect to the server using (GameTrackerConnection db = new GameTrackerConnection()) { // use the Game model to create a new Games object and // save a new record Game newGame = new Game(); Team newTeam1, newTeam2; newTeam1 = new Team(); newTeam2 = new Team(); int GameID = 0; if (Request.QueryString.Count > 0) { // get the id from url GameID = Convert.ToInt32(Request.QueryString["GameID"]); // get the current ames from EF DB newGame = (from game in db.Games where game.GameID == GameID select game).FirstOrDefault(); newTeam1 = (from team in db.Teams where team.GameID == GameID where team.TeamNo == 1 select team).FirstOrDefault(); newTeam2 = (from team in db.Teams where team.GameID == GameID where team.TeamNo == 2 select team).FirstOrDefault(); } // add form data to the new Game record newGame.GameCategory = GameCategoryDropDownList.SelectedValue; newGame.GameName = GameNameTextBox.Text; newGame.GameDesc = GameDescTextBox.Text; newGame.WeekNo = this.GetWeekNo(); newGame.EventDate = Convert.ToDateTime(EventDateTextBox.Text); newGame.SpectatorsNo = Convert.ToInt32(SpectatorTextBox.Text); if (Points1 > Points2) { newGame.GameWinner = Team1TextBox.Text; } else { newGame.GameWinner = Team2TextBox.Text; } newGame.TotalScore = Points1 + Points2; // add form data to the Team1 record newTeam1.TeamName = Team1TextBox.Text; newTeam1.TeamDesc = Team1DescTextBox.Text; newTeam1.TeamScore = Points1; newTeam1.TeamNo = 1; newTeam1.TotalScoreAllowed = PointsAllowed; // add form data to the Team2 record newTeam2.TeamName = Team2TextBox.Text; newTeam2.TeamDesc = Team2DescTextBox.Text; newTeam2.TeamScore = Points2; newTeam2.TeamNo = 2; newTeam2.TotalScoreAllowed = PointsAllowed; // use LINQ to ADO.NET to add / insert new game into the database // check to see if a new game is being added if (GameID == 0) { db.Games.Add(newGame); db.Teams.Add(newTeam1); db.Teams.Add(newTeam2); } // save our changes db.SaveChanges(); // Redirect back to the updated Dashboard page Response.Redirect("~/GameTracker/Dashboard.aspx"); } } }