/*<summary> * This Method gets the games data and puts it into the proper gridView * </summary> * * @methods getGame * @return {void} */ protected void getSoccerGame(int lowerIndex, int higherIndex) { using (comp2007db db = new comp2007db()) { var higherDate = DateTime.Now.AddDays(higherIndex); var lowerDate = DateTime.Now.AddDays(lowerIndex); var SoccerGames = (from allSoccerGames in db.games where allSoccerGames.datePlayed >= lowerDate && allSoccerGames.datePlayed <= higherDate && allSoccerGames.sportType == "Soccer" orderby allSoccerGames.datePlayed select allSoccerGames); SoccerGamesGridView.DataSource = SoccerGames.AsQueryable().ToList(); SoccerGamesGridView.DataBind(); soccerDateLabel.Text = lowerDate.ToString("yyy-MM-dd") + " - " + higherDate.ToString("yyy-MM-dd"); } }
protected void DeleteGame(object sender, GridViewDeleteEventArgs e, GridView Games) { int selectedRow = e.RowIndex; int gameId = Convert.ToInt32(Games.DataKeys[selectedRow].Values["Id"]); if (Session["userName"] == null) { Response.Redirect("Login.aspx"); } using (comp2007db db = new comp2007db()) { game deletedGame = (from gameRecord in db.games where gameRecord.Id == gameId select gameRecord).FirstOrDefault(); db.games.Remove(deletedGame); db.SaveChanges(); } }
protected void AddGameButton_Click(object sender, EventArgs e) { using (comp2007db db = new comp2007db()) { // use the syudent model to save a new record game newGame = new game(); int GameID = 0; if (Request.QueryString.Count > 0) { // get game id from url GameID = Convert.ToInt32(Request.QueryString["Id"]); // get the current Game from the DB newGame = (from game in db.games where game.Id == GameID select game).FirstOrDefault(); } // add for data to new student record newGame.homeName = homeNameTextBox.Text; newGame.awayName = awayNameTextBox.Text; newGame.homePoints = Convert.ToInt32(homePointsTextBox.Text); newGame.awayPoints = Convert.ToInt32(awayPointsTextBox.Text); newGame.attendances = Convert.ToInt32(attendancesTextBox.Text); newGame.stadium = stadiumTextBox.Text; newGame.sportType = sportTypeTextBox.SelectedValue; newGame.datePlayed = Convert.ToDateTime(datePlayedTextBox.Text); // add a new game to Games Table Collection if (GameID == 0) { db.games.Add(newGame); } // run insert commands to database db.SaveChanges(); Response.Redirect("~/Default.aspx"); } }
private void GetGame() { int GameID = Convert.ToInt32(Request.QueryString["Id"]); //connect to DB using (comp2007db db = new comp2007db()) { game updatedGame = (from game in db.games where game.Id == GameID select game).FirstOrDefault(); if (updatedGame != null) { homeNameTextBox.Text = updatedGame.homeName; awayNameTextBox.Text = updatedGame.awayName; homePointsTextBox.Text = updatedGame.homePoints.ToString(); awayPointsTextBox.Text = updatedGame.awayPoints.ToString(); attendancesTextBox.Text = updatedGame.attendances.ToString(); stadiumTextBox.Text = updatedGame.stadium; sportTypeTextBox.SelectedValue = updatedGame.sportType; datePlayedTextBox.Text = updatedGame.datePlayed.ToString("yyy-MM-dd"); } } }