Beispiel #1
0
 private void AddRoles(TeduDbContext context)
 {
     context.Roles.Add(new IdentityRole()
     {
         Id   = "Admin",
         Name = "Global Access"
     });
     context.Roles.Add(new IdentityRole()
     {
         Id   = "CanEditUser",
         Name = "Add, modify, and delete Users"
     });
     context.Roles.Add(new IdentityRole()
     {
         Id   = "CanEditGroup",
         Name = "Global Access"
     });
     context.Roles.Add(new IdentityRole()
     {
         Id   = "CanEditRole",
         Name = "Add, modify, and delete roles"
     });
     context.Roles.Add(new IdentityRole()
     {
         Id   = "User",
         Name = "Restricted to business domain activity"
     });
     // Some example initial roles. These COULD BE much more granular:
     context.SaveChanges();
 }
Beispiel #2
0
 public void AddGroups(TeduDbContext context)
 {
     foreach (var groupName in _initialGroupNames)
     {
         context.AppGroups.Add(new Model.Models.AppGroup()
         {
             Name = groupName
         });
         context.SaveChanges();
     }
 }
Beispiel #3
0
        //private void AddRolesToGroups(TeduDbContext context)
        //{
        //    // Add the Super-Admin Roles to the Super-Admin Group:
        //    IDbSet<AppGroup> allGroups = context.AppGroups;
        //    AppGroup superAdmins = allGroups.First(g => g.Name == "SuperAdmins");
        //    foreach (string name in _superAdminRoleNames)
        //    {
        //        _ro.AddRoleToGroup(superAdmins.Id, name);
        //    }

        //    // Add the Group-Admin Roles to the Group-Admin Group:
        //    AppGroup groupAdmins = context.AppGroups.First(g => g.Name == "GroupAdmins");
        //    foreach (string name in _groupAdminRoleNames)
        //    {
        //        _idManager.AddRoleToGroup(groupAdmins.Id, name);
        //    }

        //    // Add the User-Admin Roles to the User-Admin Group:
        //    AppGroup userAdmins = context.AppGroups.First(g => g.Name == "UserAdmins");
        //    foreach (string name in _userAdminRoleNames)
        //    {
        //        _idManager.AddRoleToGroup(userAdmins.Id, name);
        //    }

        //    // Add the User Roles to the Users Group:
        //    AppGroup users = context.AppGroups.First(g => g.Name == "Users");
        //    foreach (string name in _userRoleNames)
        //    {
        //        _idManager.AddRoleToGroup(users.Id, name);
        //    }
        //}

        //private void CreatePaymentMethod(TeduDbContext context)
        //{
        //    if (context.PaymentMethods.Any())
        //    {
        //        context.PaymentMethods.Add()
        //    }
        //}

        private void CreateUser(TeduDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            var manager = new UserManager <AppUser>(new UserStore <AppUser>(new TeduDbContext()));

            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new TeduDbContext()));

            var user = new AppUser()
            {
                UserName       = "******",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
                BirthDate      = DateTime.Now,
                Bio            = "Demo",
                FullName       = "Technology Education"
            };

            manager.Create(user, "123654$");

            var adminUser = manager.FindByEmail("*****@*****.**");

            manager.AddToRoles(adminUser.Id, _initialGroupNames);
        }
Beispiel #4
0
 public TeduDbContext Init()
 {
     return(dbContext ?? (dbContext = new TeduDbContext()));
 }
Beispiel #5
0
 public ApplicationUserStore(TeduDbContext context)
     : base(context)
 {
 }