public async Task <IActionResult> Edit(int id, [Bind("ID,playerUsername,playerPassword,playerWins,playerLoses")] MpPongPlayer mpPongPlayer) { if (id != mpPongPlayer.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(mpPongPlayer); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MpPongPlayerExists(mpPongPlayer.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(mpPongPlayer)); }
public async Task <IActionResult> Create([Bind("ID,playerUsername,playerPassword,playerWins,playerLoses")] MpPongPlayer mpPongPlayer) { if (ModelState.IsValid) { _context.Add(mpPongPlayer); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(mpPongPlayer)); }
public static void Initialize(MpPongPlayerContext context) { context.Database.EnsureCreated(); // Look for any players if (context.MpPongPlayers.Any()) { return; // Database has been seeded / exists } // If it doesn't exist, create some data for first time users // ID is auto incremented, no need to use it as a field. var mpPongPlayers = new MpPongPlayer[] { new MpPongPlayer { playerUsername = "******", playerPassword = "******", playerWins = 3, playerLoses = 2 }, new MpPongPlayer { playerUsername = "******", playerPassword = "******", playerWins = 2, playerLoses = 1 }, new MpPongPlayer { playerUsername = "******", playerPassword = "******", playerWins = 10, playerLoses = 2 }, new MpPongPlayer { playerUsername = "******", playerPassword = "******", playerWins = 1, playerLoses = 5 } }; foreach (MpPongPlayer mp in mpPongPlayers) { context.MpPongPlayers.Add(mp); } context.SaveChanges(); }