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 method pupulate the Gridview with games list * The method take a integer value * if its true-show the list in that date, which can be selected using calender * if its false-show the list in the week,which can be selected using the dropdown * </summary> * * @method GetGames * @returns {void} */ protected void GetGames(Boolean checker) { string sortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString(); // connect to EF using (GameTrackerConnection db = new GameTrackerConnection()) { //checks whether it list should list by date or week if (checker)//show by date { // query the games Table using EF and LINQ var Games = (from allGames in db.Games where allGames.EventDate == DateSelectorCalendar.SelectedDate select allGames); // bind the result to the GridView GamesGridView.DataSource = Games.AsQueryable().OrderBy(sortString).ToList(); GamesGridView.DataBind(); } else //show by week number { int weekNo = Convert.ToInt32(WeekNoDropDownList.SelectedValue);//converting the selected week number to the int // query the games Table using EF and LINQ var Games = (from allGames in db.Games where allGames.WeekNo == weekNo select allGames); // bind the result to the GridView GamesGridView.DataSource = Games.AsQueryable().OrderBy(sortString).ToList(); GamesGridView.DataBind(); } } }
/** * <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 gets the game being edited and enters it's data into the text fields * </summary> * @method GetGame * @return {void} * */ protected void GetGame() { // populate the form with existing data from the database int GameID = Convert.ToInt32(Request.QueryString["GameID"]); // connect to the EF DB using (GameTrackerConnection db = new GameTrackerConnection()) { // populate a game object instance with the GameID from the URL Parameter Game UpdatedGame = (from game in db.Games where game.GameID == GameID select game).FirstOrDefault(); // map the game properties to the form controls if (UpdatedGame != null) { GameNameTextBox.Text = UpdatedGame.GameName; DescriptionTextBox.Text = UpdatedGame.Description; RunsTextBox.Text = UpdatedGame.Runs.ToString(); SpectatorsTextBox.Text = UpdatedGame.Spectators.ToString(); Team1TextBox.Text = UpdatedGame.Team1; Team2TextBox.Text = UpdatedGame.Team2; WinningTeamTextBox.Text = UpdatedGame.WinningTeam; CreatedDate.Text = UpdatedGame.Created.ToString("yyyy-MM-dd"); } } }
/** * <summary> * This method connects to db and pulls out existing info for an existing game * </summary> * @method @getGameDetails * @return {void} */ protected void getGameDetails() { // populate the form with existing data from the data base int gameID = Convert.ToInt32(Request.QueryString["gameID"]); //connect to db using (GameTrackerConnection db = new GameTrackerConnection()) { Csgo updatedDetails = (from gameRecords in db.Csgoes where gameRecords.gameID == gameID select gameRecords).FirstOrDefault(); //map the game properties to the form if (updatedDetails != null) { Team1TextBox.Text = updatedDetails.team1; Team2TextBox.Text = updatedDetails.team2; RoundsForTeam1TextBox.Text = updatedDetails.roundsWon.ToString(); RoundsForTeam2TextBox.Text = updatedDetails.roundsWonTeam2.ToString(); PointsForTeam1TextBox.Text = updatedDetails.totalPoints.ToString(); PointsForTeam2TextBox.Text = updatedDetails.totalPointsTeam2.ToString(); MapPlayedTexBox.Text = updatedDetails.mapPlayed; SpectatorsTextBox.Text = updatedDetails.spectators.ToString(); WinnerTextBox.Text = updatedDetails.winner; //WeekTextBox.Text = updatedDetails.weekOfGame.ToString(); } } }
/** * <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 gets the team being edited and enters it's data into the text fields * </summary> * @method GetTeam * @return {void} * */ protected void GetTeams() { // populate the form with existing data from the database int TeamID = Convert.ToInt32(Request.QueryString["TeamID"]); // connect to the EF DB using (GameTrackerConnection db = new GameTrackerConnection()) { // populate a team object instance with the TeamID from the URL Parameter Team UpdatedTeam = (from team in db.Teams where team.TeamID == TeamID select team).FirstOrDefault(); // map the team properties to the form controls if (UpdatedTeam != null) { TeamNameTextBox.Text = UpdatedTeam.TeamName; DescriptionTextBox.Text = UpdatedTeam.Description; SportTextBox.Text = UpdatedTeam.Sport; CityTextBox.Text = UpdatedTeam.City; TotalRunsTextBox.Text = UpdatedTeam.TotalRuns.ToString(); AllowedRunsTextBox.Text = UpdatedTeam.AllowedRuns.ToString(); } } }
/** * <summary> * This method connects to db and pulls out existing info for an existing game * </summary> * @method @getGameDetails * @return {void} */ protected void getGameDetails() { // populate the form with existing data from the data base int gameID = Convert.ToInt32(Request.QueryString["gameID"]); //connect to db using (GameTrackerConnection db = new GameTrackerConnection()) { Smite updatedDetails = (from gameRecords in db.Smites where gameRecords.gameID == gameID select gameRecords).FirstOrDefault(); //map the game properties to the form if (updatedDetails != null) { Team1SmiteTextBox.Text = updatedDetails.team1; Team2SmiteTextBox.Text = updatedDetails.team2; KillsForTeam1TextBox.Text = updatedDetails.killsTeam1.ToString(); KillsForTeam2TextBox.Text = updatedDetails.killsTeam2.ToString(); PointsSmiteForTeam1TextBox.Text = updatedDetails.pointsTeam1.ToString(); PointsSmiteForTeam2TextBox.Text = updatedDetails.pointsTeam2.ToString(); SpectatorsSmiteTextBox.Text = updatedDetails.spectators.ToString(); WinnerSmiteTextBox.Text = updatedDetails.winner; //WeekTextBox.Text = updatedDetails.weekOfGame.ToString(); } } }
/** * <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 sorts out the games played by week * </summary> * @method csgoSort * @returns {VOID} * */ protected void csgoSort(object sender, EventArgs e) { //checks to see if the week field is empty if (weekNumberSort.Text == null) { Response.Redirect("~/Csgo.aspx"); } else { string week = weekNumberSort.Text; //store the input into a string string[] weekArray = null; char[] splitChar = { 'W' }; //split the input into 2 parts the year will be stored in weekArray[0] and the week number is stored in the second index of the array weekArray = week.Split(splitChar); string weekNum = weekArray[1]; // store just the week number into a string variable int weekSort = int.Parse(weekNum); // parse the number as an integer //connect to EF using (GameTrackerConnection db = new GameTrackerConnection()) { //query the csgo table var Csgo = (from allData in db.Csgoes where allData.weekOfGame == weekSort select allData); //bind results to the gridview CsgoGridView.DataSource = Csgo.ToList(); CsgoGridView.DataBind(); } } }
/** * <summary> * This method gets the teams from the database * </summary> * @method GetTeams * @return {void} * */ protected void GetTeams() { //connect to EF using (GameTrackerConnection db = new GameTrackerConnection()) { //query the teams table using EF and LINQ var Teams = (from allTeams in db.Teams select allTeams); //bind results to gridview TeamsGridView.DataSource = Teams.AsQueryable().ToList(); TeamsGridView.DataBind(); } }
/** * <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 gets the dota data from the DB * </summary> * @method GetSmiteData * @returns {void} * */ protected void GetSmiteData() { //connect to EF using (GameTrackerConnection db = new GameTrackerConnection()) { //query the csgo table var Smite = (from allData in db.Smites select allData); //bind results to the gridview SmiteGridView.DataSource = Smite.ToList(); SmiteGridView.DataBind(); } }
/** * * <summary> * This method gets the dota data from the DB * </summary> * @method GetDotaData * @returns {void} * */ protected void GetDotaData() { //connect to EF using (GameTrackerConnection db = new GameTrackerConnection()) { //query the csgo table var Dota = (from allData in db.Dotas select allData); //bind results to the gridview DotaGridView.DataSource = Dota.ToList(); DotaGridView.DataBind(); } }
/** * * <summary> * This method gets the csgo data from the DB * </summary> * @method GetCsgoData * @returns {void} * */ protected void GetCsgoData() { //connect to EF using (GameTrackerConnection db = new GameTrackerConnection()) { //query the csgo table var Csgo = (from allData in db.Csgoes select allData); //bind results to the gridview CsgoGridView.DataSource = Csgo.ToList(); CsgoGridView.DataBind(); } }
/** * <summary> * This method pupulate the Gridview with games list * </summary> * * @method GetGames * @returns {void} */ protected void GetGames() { string sortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString(); // connect to EF using (GameTrackerConnection db = new GameTrackerConnection()) { // query the games Table using EF and LINQ var Games = (from allGames in db.Games select allGames); // bind the result to the GridView GamesGridView.DataSource = Games.AsQueryable().OrderBy(sortString).ToList(); GamesGridView.DataBind(); } }
/** * <summary> * This method gets teamnames and enters them into the team name dropdown lists * </summary> * @method GetTeamNames * @return {void} * */ protected void GetTeamNames() { //connect to EF using (GameTrackerConnection db = new GameTrackerConnection()) { //query the teams table using EF and LINQ var Teams = (from allTeamNames in db.Teams select allTeamNames.TeamName); //adds team names to Team1dropdownlist Team1DropDownList.DataSource = Teams.AsQueryable().ToList(); Team1DropDownList.DataBind(); //adds team names to Team2dropdownlist Team2DropDownList.DataSource = Teams.AsQueryable().ToList(); Team2DropDownList.DataBind(); } }
protected void GetUser() { string UserID = Request.QueryString.ToString(); using (GameTrackerConnection db = new GameTrackerConnection()) { AspNetUser updatedUser = (from user in db.AspNetUsers where user.Id == UserID select user).FirstOrDefault(); UserNameTextBox.Text = updatedUser.UserName; PhoneNumberTextBox.Text = updatedUser.PhoneNumber; EmailTextBox.Text = updatedUser.Email; } }
/** * <summary> * This method pupulate the Gridview with teams list * </summary> * * @method GetTeams * @returns * */ protected void GetTeams() { // populate the form with existing gmae data from the db int GameID = Convert.ToInt32(Request.QueryString["GameID"]); // connect to EF using (GameTrackerConnection db = new GameTrackerConnection()) { // query the games Table using EF and LINQ var Teams = (from allTeam in db.Teams where allTeam.GameID == GameID select allTeam); // bind the result to the GridView TeamsGridView.DataSource = Teams.AsQueryable().ToList(); TeamsGridView.DataBind(); } }
/** * <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"); } }
/** * <summary> * This method pupulate the form with all the details * </summary> * * @method GetGames * @returns {void} */ protected void GetGames() { // populate the form with existing gmae data from the db int GameID = Convert.ToInt32(Request.QueryString["GameID"]); // connect to the EF DB using (GameTrackerConnection db = new GameTrackerConnection()) { // populate a game instance with the GameID from the URL parameter Game updatedGame = (from game in db.Games where game.GameID == GameID select game).FirstOrDefault(); Team updatedTeam1 = (from team in db.Teams where team.GameID == GameID where team.TeamNo == 1 select team).FirstOrDefault(); Team updatedTeam2 = (from team in db.Teams where team.GameID == GameID where team.TeamNo == 2 select team).FirstOrDefault(); // map the game properties to the form controls if (updatedGame != null) { GameCategoryDropDownList.SelectedValue = updatedGame.GameCategory; GameNameTextBox.Text = updatedGame.GameName; GameDescTextBox.Text = updatedGame.GameDesc; EventDateTextBox.Text = updatedGame.EventDate.ToString("yyyy-MM-dd"); SpectatorTextBox.Text = updatedGame.SpectatorsNo.ToString(); Team1TextBox.Text = updatedTeam1.TeamName; Team1DescTextBox.Text = updatedTeam1.TeamDesc; Team1PointsTextBox.Text = updatedTeam1.TeamScore.ToString(); PointsAllowedTextBox.Text = updatedTeam1.TotalScoreAllowed.ToString(); Team2TextBox.Text = updatedTeam2.TeamName; Team2DescTextBox.Text = updatedTeam2.TeamDesc; Team2PointsTextBox.Text = updatedTeam2.TeamScore.ToString(); } } }
/** * <summary> * This method gets the games from the database and puts them into the gridview based on the date specified in the dropdown menu * </summary> * @method GetGames * @return {void} * */ protected void GetGames() { //connect to EF using (GameTrackerConnection db = new GameTrackerConnection()) { DateTime date1 = new DateTime(); DateTime date2 = new DateTime(); date1 = Convert.ToDateTime(TrackingWeekDropDown.SelectedValue); date2 = Convert.ToDateTime(TrackingWeekDropDown.Items[TrackingWeekDropDown.SelectedIndex + 1].Value); //query the Games table using EF and LINQ var Games = (from allGames in db.Games where allGames.Created >= date1.Date && allGames.Created < date2.Date select allGames); //bind results to gridview GamesGridView.DataSource = Games.AsQueryable().ToList(); GamesGridView.DataBind(); TrackingDateLabel.Text = date1.ToString("MMMM dd, yyyy") + " To " + date2.ToString("MMMM dd, yyyy"); } }
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"); } } }