public async Task <ActionResult <Player> > Create([FromBody] Player player) { await context.Players.AddAsync(player); await context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetById), new { id = player.PlayerId }, player)); }
public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,Age,SkillLevel,Email")] Player player) { //Validate the information, and save only if valid if (ModelState.IsValid) { detailsPlayerContext.Add(player); await detailsPlayerContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index), "Home")); } //Information not valid, return to Add Player page return(View(player)); }
public async Task <IActionResult> RemovePlayer(int id) { //Locate the player identified by the ID primary key var player = await homePlayerContext.Player.FindAsync(id); //Remove the player homePlayerContext.Player.Remove(player); //Save the changes await homePlayerContext.SaveChangesAsync(); //Go back to the main page return(RedirectToAction(nameof(Index))); }