public ActionResult Create(int?teamId) { Team t = db.teamDB.Find(teamId); if (t == null) { return(Content("Team not found")); } ModelAddFootballPlayerToTeam model = new ModelAddFootballPlayerToTeam(); model.footballPlayer = new FootballPlayer(); model.footballPlayer.TeamId = t.id; model.team = t; return(View(model)); }
public ActionResult Create([Bind(Include = "footballPlayer,team")] ModelAddFootballPlayerToTeam model) { Team t = db.teamDB.Find(model.footballPlayer.TeamId); if (t.footballPlayers.ToList().Count == 11) { return(Content("The team " + t.name + " has 11 players. Adding " + model.footballPlayer.name + " failed")); } if (ModelState.IsValid) { db.footballPlayerDB.Add(model.footballPlayer); db.SaveChanges(); return(RedirectToAction("Details", "Team", new { id = model.footballPlayer.TeamId })); } return(View(model)); }