コード例 #1
0
        public GenericRepository(TweeterAppDbContext context)
        {
            if (context == null)
            {
                throw new ArgumentException("An instance of DbContext is required to use this repository.", "context");
            }

            this.Context = context;
            this.DbSet   = this.Context.Set <T>();
        }
コード例 #2
0
        private void SeedUsers(TweeterAppDbContext context)
        {
            var adminUser = new User
            {
                Email    = "*****@*****.**",
                UserName = "******"
            };

            this.userManager.Create(adminUser, "123456");
            this.userManager.AddToRole(adminUser.Id, "Admin");
        }
コード例 #3
0
        protected override void Seed(TweeterAppDbContext context)
        {
            if (context.Users.Any())
            {
                return;
            }

            this.userManager = new UserManager <User>(new UserStore <User>(context));

            this.SeedRoles(context);
            this.SeedUsers(context);
            base.Seed(context);
        }
コード例 #4
0
 private void SeedRoles(TweeterAppDbContext context)
 {
     context.Roles.AddOrUpdate(x => x.Name, new IdentityRole("Admin"));
     context.SaveChanges();
 }