public TeamService(TeamsContext context) { _context = context; if (!_context.Teams.Any() && !init) { SeedDatabase(_context); } }
protected override void Seed(ProjectBetterTeams.TeamsContext context) { UserSignUp pass = new UserSignUp(); Users user = new Users() { Username = "******", Password = pass.EncryptPassword("Admin"), FirstName = "Panagiotis", LastName = "Papadopoulos", DateOFBirth = DateTime.Parse("1992/02/28").Date, UserType = "SuperAdmin" }; using (var db = new TeamsContext()) { db.Users.AddOrUpdate(user); db.SaveChanges(); } }
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 TeamsController(TeamsContext context) { _context = context; }