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);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
 private void btnSubmit_Click(object sender, RoutedEventArgs e)
 {
     if (!String.IsNullOrWhiteSpace(tbxUsername.Text) && !String.IsNullOrWhiteSpace(pbxPassword.Password) && !String.IsNullOrWhiteSpace(pbxConfirmPassword.Password))
     {
         if (pbxConfirmPassword.Password.Equals(pbxPassword.Password))
         {
             using (var db = new PokedexTeamBuilderDBEntities())
             {
                 var query    = db.Users.Where(u => u.username == tbxUsername.Text);
                 var loadUser = query.ToList();
                 if (loadUser.Count == 0)
                 {
                     User newUser = new User()
                     {
                         username = tbxUsername.Text,
                         password = pbxPassword.Password
                     };
                     db.Users.Add(newUser);
                     db.SaveChanges();
                     var window = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault();
                     window.isLoggedIn = true;
                     window.username   = tbxUsername.Text;
                     Views.Home home = new Views.Home();
                     NavigationService.Navigate(home);
                 }
                 else
                 {
                     DisplayError("The username already exists.");
                 }
             }
         }
         else
         {
             DisplayError("The password and confirm password do not match.");
         }
     }
     else
     {
         DisplayError("One or more of the fields were left blank.");
     }
 }