public async Task <IActionResult> Edit(int id, [Bind("ID,Name,BaseballLeagueID")] BaseballDivision baseballDivision) { if (id != baseballDivision.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _db.Update(baseballDivision); await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BaseballDivisionExists(baseballDivision.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["BaseballLeagueID"] = new SelectList(_db.BaseballLeagues, "ID", "Name", baseballDivision.BaseballLeagueID); return(View(baseballDivision)); }
public async static Task GetData(ApplicationDbContext _db) { int americanLeagueID = (await _db.BaseballLeagues .FirstOrDefaultAsync(x => x.Name == "American League")).ID; int nationalLeagueID = (await _db.BaseballLeagues .FirstOrDefaultAsync(x => x.Name == "National League")).ID; var baseballDivisions = new BaseballDivision[] { new BaseballDivision { Name = "American League East ", BaseballLeagueID = americanLeagueID }, new BaseballDivision { Name = "American League Central", BaseballLeagueID = americanLeagueID }, new BaseballDivision { Name = "American League West", BaseballLeagueID = americanLeagueID }, new BaseballDivision { Name = "National League East", BaseballLeagueID = nationalLeagueID }, new BaseballDivision { Name = "National League Central", BaseballLeagueID = nationalLeagueID }, new BaseballDivision { Name = "National League West", BaseballLeagueID = nationalLeagueID }, }; _db.BaseballDivisions.AddRange(baseballDivisions); _db.SaveChanges(); }
public async Task <IActionResult> Create([Bind("ID,Name,BaseballLeagueID")] BaseballDivision baseballDivision) { if (ModelState.IsValid) { _db.Add(baseballDivision); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BaseballLeagueID"] = new SelectList(_db.BaseballLeagues, "ID", "Name", baseballDivision.BaseballLeagueID); return(View(baseballDivision)); }