Beispiel #1
0
        private async Task CreateUserRoles(IServiceProvider serviceProvider)
        {
            RoleManager <IdentityRole> roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >();
            WhizMAContext  Context = serviceProvider.GetRequiredService <WhizMAContext>();
            IdentityResult roleResult;

            // Adding Admin Role.
            bool roleCheck = await roleManager.RoleExistsAsync("Administrator");

            if (!roleCheck)
            {
                // create the roles and seed them to the database.
                roleResult = await roleManager.CreateAsync(new IdentityRole("Administrator"));
            }
            // Assign Admin role to the main user.
            IdentityUser user = Context.Users.FirstOrDefault(u => u.Email == "*****@*****.**");

            if (user != null)
            {
                DbSet <IdentityUserRole <string> > roles = Context.UserRoles;
                IdentityRole adminRole = Context.Roles.FirstOrDefault(r => r.Name == "Administrator");
                if (adminRole != null)
                {
                    if (!roles.Any(ur => ur.UserId == user.Id && ur.RoleId == adminRole.Id))
                    {
                        roles.Add(new IdentityUserRole <string>()
                        {
                            UserId = user.Id, RoleId = adminRole.Id
                        });
                        Context.SaveChanges();
                    }
                }
            }
        }
Beispiel #2
0
 public BundelWinkelController(WhizMAContext context)
 {
     _context = context;
 }
 public CursusWinkelController(WhizMAContext context)
 {
     _context = context;
 }
Beispiel #4
0
 public LesController(WhizMAContext context)
 {
     _context = context;
 }
Beispiel #5
0
 public GenericRepository(WhizMAContext context)
 {
     _context = context;
 }
 public AlertItemsController(WhizMAContext context)
 {
     _context = context;
 }
Beispiel #7
0
 public CursusBeschrijvingController(WhizMAContext context)
 {
     _context = context;
 }
 public UnitOfWork(WhizMAContext context)
 {
     _context = context;
 }
Beispiel #9
0
 public AccountCatalogusController(WhizMAContext context)
 {
     _context = context;
 }
Beispiel #10
0
 public DocentController(WhizMAContext context)
 {
     _context = context;
 }
Beispiel #11
0
 public HomeController(ILogger <HomeController> logger, WhizMAContext context)
 {
     _context = context;
     _logger  = logger;
 }