public NflController(NflContext context) { _context = context; if (_context.Players.Count() == 0 && _context.Teams.Count() == 0 && _context.Teams.Count() <= 15) { _context.Players.Add(new Player { Id = 1, FirstName = "Tom", LastName = "Brady" }); _context.Players.Add(new Player { Id = 2, FirstName = "Larry", LastName = "FitzGerald" }); _context.Players.Add(new Player { Id = 3, FirstName = "Cam", LastName = "Newton" }); _context.Players.Add(new Player { Id = 4, FirstName = "Eli", LastName = "Manning" }); _context.Players.Add(new Player { Id = 5, FirstName = "Odell", LastName = "Beckham" }); _context.Players.Add(new Player { Id = 6, FirstName = "Richard", LastName = "Sherman" }); _context.Players.Add(new Player { Id = 7, FirstName = "Aaron", LastName = "Donald" }); _context.Teams.Add(new Team { Id = 1, Name = "New England Patriots", Location = "Foxborough, MA" }); _context.Teams.Add(new Team { Id = 2, Name = "Arizona Cardinals", Location = "Glendale, AZ" }); _context.Teams.Add(new Team { Id = 3, Name = "Carolina Panthers", Location = "Charlotte, NC" }); _context.Teams.Add(new Team { Id = 4, Name = "New York Giants", Location = "East Rutherford, NJ" }); _context.Teams.Add(new Team { Id = 5, Name = "Cleveland Browns", Location = "Cleveland, OH" }); _context.Teams.Add(new Team { Id = 6, Name = "San Francisco 49ers", Location = "Santa Clara, CA" }); _context.Teams.Add(new Team { Id = 7, Name = "Los Angeles Rams", Location = "Los Angeles, CA" }); _context.SaveChanges(); _context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; } }
public IActionResult CreateTeam([FromBody] Team team) { //_context.Teams.Add(team); //await _context.SaveChangesAsync(); //return CreatedAtAction(nameof(GetTeamsById), new {id = team.Id}, team); if (ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Teams.Add(team); _context.SaveChanges(); return(Ok()); }