static void SeedDatabase(TeamsContext ctx) { Team ferrari = new Team { Name = "Ferrari", FoundedIn = 1899, CheckPaid = false, ChampionshipsWon = 12 }; Team mclaren = new Team { Name = "McLaren", FoundedIn = 1910, CheckPaid = true, ChampionshipsWon = 3 }; Team mercedes = new Team { Name = "Mercedes-Benz", FoundedIn = 1960, CheckPaid = true, ChampionshipsWon = 25 }; //Add admin var user = new IdentityUser("admin"); user.PasswordHash = new PasswordHasher <IdentityUser>().HashPassword(user, ctx.GetService <IConfiguration>().GetSection("Password").Value); var userStore = ctx.GetService <UserManager <IdentityUser> >(); userStore.CreateAsync(user); ctx.Add(ferrari); ctx.Add(mercedes); ctx.Add(mclaren); ctx.SaveChanges(); init = true; }
public async Task <IActionResult> Create([Bind("Id,Name,City,bestPlayer")] Teams teams) { if (ModelState.IsValid) { _context.Add(teams); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(teams)); }
public async Task <IActionResult> AddOrEdit([Bind("TeamsId,TeamName,LeaderName,CallNumber,TeamLocation")] Teams teams) { if (ModelState.IsValid) { if (teams.TeamsId == 0) { _context.Add(teams); } else { _context.Update(teams); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(teams)); }