private void SavePokemon(object sender, RoutedEventArgs e)
        {
            Pokemon      p            = new Pokemon();
            PokemonModel pokemonQuery = res.Where(pok => pok.name == (pokéListBox.Items.GetItemAt(pokéListBox.SelectedIndex) as PokemonModel).name).FirstOrDefault();

            p.move1       = Move1Box.SelectedValue.ToString();
            p.move2       = Move2Box.SelectedValue.ToString();
            p.move3       = Move3Box.SelectedValue.ToString();
            p.move4       = Move4Box.SelectedValue.ToString();
            p.TeamID      = previousTeam.TeamID;
            p.PokemonName = pokemonQuery.name;

            using (var db = new PokedexTeamBuilderDBEntities())
            {
                var query = db.Teams.Where(t => t.TeamID == previousTeam.TeamID).FirstOrDefault();
                if (pokemonToEdit != null)
                {
                    query.Pokemons.Remove(db.Pokemons.Where(pok => pok.PokemonID == pokemonToEdit.PokemonID).FirstOrDefault());
                }
                query.Pokemons.Add(p);

                db.SaveChanges();
            }

            ViewTeam teamPage = new ViewTeam();

            this.NavigationService.Navigate(teamPage);
        }
예제 #2
0
        //Adds a team to the database under current users id
        private void AddTeam(object sender, RoutedEventArgs e)
        {
            Team t = new Team();

            using (var db = new PokedexTeamBuilderDBEntities())
            {
                t.User   = db.Users.Where(u => u.username == window.username).First();
                t.UserID = t.User.UserID;

                db.Teams.Add(t);
                db.SaveChanges();
            }

            ViewTeam teamPage = new ViewTeam();

            this.NavigationService.Navigate(teamPage);
        }
예제 #3
0
        private void DeletePokemon(object sender, RoutedEventArgs e)
        {
            using (var db = new PokedexTeamBuilderDBEntities())
            {
                var            query    = db.Pokemons.Where(p => p.TeamID == currentTeam.TeamID);
                List <Pokemon> toRemove = query.ToList();
                foreach (var pokemon in toRemove)
                {
                    db.Pokemons.Remove(pokemon);
                }
                db.SaveChanges();
                Team team = db.Teams.Where(t => t.TeamID == currentTeam.TeamID).FirstOrDefault();
                db.Teams.Remove(team);
                db.SaveChanges();
            }

            ViewTeam teamPage = new ViewTeam();

            this.NavigationService.Navigate(teamPage);
        }
        private void TeamView(object sender, RoutedEventArgs e)
        {
            ViewTeam teamPage = new ViewTeam();

            this.NavigationService.Navigate(teamPage);
        }