public ActionResult Edit([Bind(Include = "teamID,teamName")] Team team) { if (ModelState.IsValid) { db.Entry(team).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(team)); }
public ActionResult Create([Bind(Include = "teamID,teamName")] Team team) { if (ModelState.IsValid) { db.Teams.Add(team); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(team)); }
public ActionResult Create([Bind(Include = "positionCode,positionDescription")] Position position) { if (ModelState.IsValid) { db.Positions.Add(position); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(position)); }
public ActionResult Create([Bind(Include = "playerID,playerLastName,playerFirstName,positionCode,teamID")] Player player) { if (ModelState.IsValid) { db.Players.Add(player); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.positionCode = new SelectList(db.Positions, "positionCode", "positionDescription", player.positionCode); ViewBag.teamID = new SelectList(db.Teams, "teamID", "teamName", player.teamID); return(View(player)); }
public async Task <IActionResult> DeleteTeam(int id) { var team = await _db.Teams.FindAsync(id); var faTeam = await _db.Teams.FirstOrDefaultAsync(team => team.TeamName == "Free Agents"); List <Player> model = _db.Players .Where(player => player.Team == team.TeamName).ToList(); foreach (Player player in model) { player.Team = faTeam.TeamName; faTeam.Players.Add(player); _db.SaveChanges(); } if (team == null) { return(NotFound()); } _db.Teams.Remove(team); await _db.SaveChangesAsync(); return(NoContent()); }
public static void PrepareContext() { var options = new DbContextOptionsBuilder <NBAContext>().UseInMemoryDatabase(databaseName: "nbaDB").Options; _context = new NBAContext(options); PreparePlayers(); _context.SaveChanges(); }
public void SaveChanges() { _context.SaveChanges(); }