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");
                }
            }
        }
        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;
            }
        }
        private void setGame()
        {
            int gameId = Convert.ToInt32(Request.QueryString["gameId"]);

            using (GameTrackerContext db = new GameTrackerContext("GameTrackerConnection")) {
                var game = (from _game in db.Games
                            where _game.ID == gameId
                            select _game).FirstOrDefault();

                if (game != null)
                {
                    this.gameId       = game.ID;
                    title.Value       = game.mainTitle;
                    description.Value = game.description;
                    spectators.Value  = Convert.ToString(game.spectators);
                    weekNumber.Value  = Convert.ToString(game.weekNumber);
                    score1.Value      = Convert.ToString(game.team1Score);
                    score2.Value      = Convert.ToString(game.team2Score);

                    int ix = 0;
                    foreach (ListItem item in teams1ListBox.Items)
                    {
                        if (item.Value.Equals(Convert.ToString(game.team1Id)))
                        {
                            teams1ListBox.SelectedIndex = ix;
                            break;
                        }
                        ix++;
                    }
                    ix = 0;
                    foreach (ListItem item in teams2ListBox.Items)
                    {
                        if (item.Value.Equals(Convert.ToString(game.team2Id)))
                        {
                            teams2ListBox.SelectedIndex = ix;
                            break;
                        }
                        ix++;
                    }

                    editButton.Text = "Edit Game";
                }
            }
        }
Exemplo n.º 4
0
        private void setTeam()
        {
            int teamId = Convert.ToInt32(Request.QueryString["teamId"]);

            using (GameTrackerContext db = new GameTrackerContext("GameTrackerConnection")) {
                var team = (from _team in db.Teams
                            where _team.ID == teamId
                            select _team).FirstOrDefault();

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

                    editButton.Text = "Edit Team";
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                errorBox.Visible   = false;
                errorBox.InnerText = "";

                using (GameTrackerContext db = new GameTrackerContext("GameTrackerConnection")) {
                    teams1 = (from _team in db.Teams select _team).ToList();
                    setTeams1();

                    teams2 = (from _team in db.Teams select _team).ToList();
                    setTeams2();
                }

                if (Request.QueryString.Count > 0)
                {
                    setGame();
                }
            }
        }
Exemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Debug.WriteLine("Page was loaded");

            using (GameTrackerContext db = new GameTrackerContext("GameTrackerConnection")) {
                var _games = (from allGames in db.Games
                              select allGames).ToList();

                this.allGames = _games;

                if (allGames.Count > 0)
                {
                    lastGame = allGames.ElementAt(0);
                }

                if (allGames.Count > 1)
                {
                    otherGames = allGames.GetRange(1, allGames.Count - 1);
                }
                else
                {
                    otherGames = new List <Game>();
                }

                Debug.WriteLine("There are # games in DB: " + allGames.Count);

                var _teams = (from allTeams in db.Teams
                              select allTeams).ToList();

                Debug.WriteLine("There are # teams: " + _teams.Count);

                foreach (var team in _teams)
                {
                    Debug.WriteLine(team.name);
                }

                this.allTeams = _teams;
            }
        }
Exemplo n.º 7
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;
            }
        }