private async Task CreateUserRoles(IServiceProvider serviceProvider, StreamNightAccountDbContext dbContext) { dbContext.Database.Migrate(); var RoleManager = serviceProvider.GetRequiredService <RoleManager <StreamNightRole> >(); //Adding Admin Role bool adminRoleCheck = await RoleManager.RoleExistsAsync("Administrator"); if (!adminRoleCheck) { //create the roles and seed them to the database _ = await RoleManager.CreateAsync(new StreamNightRole("Administrator")); } //Adding Moderator Role bool streamRoleCheck = await RoleManager.RoleExistsAsync("StreamController"); if (!streamRoleCheck) { //create the roles and seed them to the database _ = await RoleManager.CreateAsync(new StreamNightRole("StreamController")); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider services, StreamNightAccountDbContext chatContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); } app.UseStaticFiles(); // HTTPS is handled upstream by Caddy. // app.UseHttpsRedirection(); app.UseRouting(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseAuthorization(); app.UseCors(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapRazorPages(); endpoints.MapHub <BridgeHub>("/bridgehub"); endpoints.MapHub <StatusHub>("/admin/statushub"); endpoints.MapHub <TwitchHub>("/admin/twitchhub"); }); CreateUserRoles(services, chatContext).Wait(); }