コード例 #1
0
        protected void deleteGame_click(object sender, EventArgs e)
        {
            int gameID = 0;

            // Check if query string value exists
            if (!String.IsNullOrEmpty(Request.QueryString["gameID"]))
            {
                // Query string value is there so now use it
                gameID = Convert.ToInt32(Request.QueryString["gameID"]);
            }


            if (gameID > 0)
            {
                // use EF and LINQ to find the selected game and delete it from DB!
                using (GameTrackerContext db = new GameTrackerContext("GameTrackerConnection")) {
                    // create a Game object and store the query inside it
                    Game toBeDeleted = (from game in db.Games
                                        where game.ID == gameID
                                        select game).FirstOrDefault();

                    // remove and save!
                    db.Games.Remove(toBeDeleted);
                    db.SaveChanges();

                    // Go back to the home page
                    Response.Redirect("Default.aspx");
                }
            }
        }
コード例 #2
0
        protected void editGame_click(object sender, EventArgs e)
        {
            try {
                using (GameTrackerContext db = new GameTrackerContext("GameTrackerConnection")) {
                    int gameId = Convert.ToInt32(Request.QueryString["gameId"]);

                    Game game = null;

                    if (gameId == 0)
                    {
                        game = new Game();
                        db.Games.Add(game);
                    }
                    else
                    {
                        game = (from _game in db.Games
                                where _game.ID == gameId
                                select _game).FirstOrDefault();
                    }

                    if (game != null)
                    {
                        game.team1Id = Convert.ToInt32(teams1ListBox.SelectedItem.Value);
                        game.team2Id = Convert.ToInt32(teams2ListBox.SelectedItem.Value);

                        game.spectators = Convert.ToInt32(spectators.Value);
                        game.team1Score = Convert.ToInt32(score1.Value);
                        game.team2Score = Convert.ToInt32(score2.Value);

                        game.mainTitle   = title.Value;
                        game.description = description.Value;
                        game.weekNumber  = Convert.ToInt32(weekNumber.Value);

                        validateGame(game);
                    }

                    // save the team
                    db.SaveChanges();

                    Response.Redirect("~/Default.aspx");
                }
            } catch (Exception ex) {
                errorBox.Visible   = true;
                errorBox.InnerText = ex.Message;
            }
        }
コード例 #3
0
        protected void editTeam_click(object sender, EventArgs e)
        {
            try {
                using (GameTrackerContext db = new GameTrackerContext("GameTrackerConnection")) {
                    int teamId = Convert.ToInt32(Request.QueryString["teamId"]);

                    Team team = null;

                    if (teamId == 0)
                    {
                        team = new Team();
                        db.Teams.Add(team);
                    }
                    else
                    {
                        team = (from _team in db.Teams
                                where _team.ID == teamId
                                select _team).FirstOrDefault();
                    }

                    if (team != null)
                    {
                        team.name        = name.Value;
                        team.logoPath    = logoPath.Value;
                        team.description = description.Value;
                    }

                    // save the team
                    db.SaveChanges();

                    Response.Redirect("~/Default.aspx");
                }
            } catch (Exception ex) {
                errorBox.Visible   = true;
                errorBox.InnerText = ex.Message;
            }
        }