예제 #1
0
 public TeamService(TeamsContext context)
 {
     _context = context;
     if (!_context.Teams.Any() && !init)
     {
         SeedDatabase(_context);
     }
 }
예제 #2
0
        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();
            }
        }
예제 #3
0
        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;
        }
예제 #4
0
 public TeamsController(TeamsContext context)
 {
     _context = context;
 }