//Populates the listbox from the database table pokemon public void PopulateListBox() { using (var db = new PokedexContext()) { ListBoxPokemon.ItemsSource = db.Pokemon.ToList(); } }
// search pokemon name comparing the search bar text to pname column of pokemon table private void SearchBar_TextChanged(object sender, TextChangedEventArgs e) { using (var db = new PokedexContext()) { var query = from pName in db.Pokemon select pName; if (!string.IsNullOrEmpty(SearchBar.Text)) { query = query.Where(e => e.Pname.StartsWith(SearchBar.Text)); ListBoxPokemon.ItemsSource = query.ToList(); } else { ListBoxPokemon.ItemsSource = null; } } }
//saves the data within the respective tables and columns private void Create_Click(object sender, RoutedEventArgs e) { //Pokecreate textblock element becomes visible Pokecreate.Visibility = Visibility.Visible; using (var db = new PokedexContext()) { Pokemon newPokemon = new Pokemon() { Pimage = TextImage.Text, Pname = TextName.Text, Ptype = TextType.Text, Pdescription = TextDescription.Text, Pheight = TextHeight.Text, Pweight = TextWeight.Text, Pcry = TextCry.Text, Psound = TextSound.Text }; Stats newStats = new Stats() { Hp = TextHP.Text, Attack = TextAttack.Text, Defense = TextType.Text, SpAttack = TextSpAttack.Text, SpDefense = TextSpDefense.Text, Speed = TextSpeed.Text }; //add to database db.Add(newPokemon); //add to database db.Add(newStats); // write changes to database db.SaveChanges(); } }
public PokemonController(PokedexContext context, IConfigurationRoot config, IHostingEnvironment host) { _context = context; _config = config; _environment = host; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, PokedexContext pokeDb, UserManager <User> um) { //ensure db is created/seeded pokeDb.Setup(env); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseApplicationInsightsRequestTelemetry(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseApplicationInsightsExceptionTelemetry(); app.UseStaticFiles(); app.UseIdentity(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }