// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, RoleManager <IdentityRole> roleManager, UserManager <IdentityUser> userManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseIdentity(); app.UseAuthentication(); UserRoleSeed URS = new UserRoleSeed(roleManager, userManager); URS.Seed(); app.UseMvc(routes => { routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}") .MapRoute("article", "{controller=Articles}/{action=Index}/{id?}") .MapRoute("comment", "{controller=Comments}/{action=Index}/{id?}") .MapRoute("comment", "{controller=Articles}/{action=Details}/{id?}") .MapRoute("comment", "{controller=Comments}/{action=Create}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, UserRoleSeed seed) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); //app.UseBrowserLink(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseAuthentication(); app.UseStatusCodePagesWithReExecute("/error/{0}"); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); seed.SeedAsync(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext dbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); UserRoleSeed.SeedData(dbContext); //PlatformSeed.SeedData(dbContext); //CategoriesSeed.SeedData(dbContext); }
private static void CreateUserRoles(IHost wh) { ILogger <Program> logger; SensateSqlContext ctx; using var scope = wh.Services.CreateScope(); var services = scope.ServiceProvider; logger = services.GetRequiredService <ILogger <Program> >(); try { logger.LogInformation("Creating user roles.."); ctx = services.GetRequiredService <SensateSqlContext>(); var roles = services.GetRequiredService <RoleManager <SensateRole> >(); var manager = services.GetRequiredService <UserManager <SensateUser> >(); var countTask = roles.Roles.CountAsync(); countTask.Wait(); if (countTask.Result > 0) { return; } var tsk = UserRoleSeed.Initialize(ctx, roles, manager); tsk.Wait(); } catch (Exception ex) { logger.LogError($"Unable to create user roles: {ex.Message}"); } }
protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); RoleSeed.Seed(builder); UserSeed.Seed(builder); UserRoleSeed.Seed(builder); }
/// <summary> /// Method to set seeds into database. /// </summary> public static void SetSeeds() { using var db = new SSOContext(); if (!db.Users.Any()) { CompanySeed.SetSeeds(db); PermissionSeed.SetSeeds(db); UserSeed.SetSeeds(db); RoleSeed.SetSeeds(db); UserParamsSeed.SetSeeds(db); RolePermissionSeed.SetSeeds(db); UserRoleSeed.SetSeeds(db); CompanyAirportsSeed.SetSeeds(db); } }
protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); builder.Entity <AppUser>().HasMany <Chat>().WithOne(m => m.GetUser_1).OnDelete(DeleteBehavior.Restrict); builder.Entity <AppUser>().HasMany <Chat>().WithOne(m => m.GetUser_2).OnDelete(DeleteBehavior.Restrict); builder.Entity <Chat>().HasOne <AppUser>().WithMany(m => m.GetChates_1).OnDelete(DeleteBehavior.Restrict); builder.Entity <Chat>().HasOne <AppUser>().WithMany(m => m.GetChates_2).OnDelete(DeleteBehavior.Restrict); RoleSeed.Seed(builder); UserSeed.Seed(builder); UserRoleSeed.Seed(builder); CountrySeed.Seed(builder); CitySeed.Seed(builder); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var serviceProvider = services.GetRequiredService <IServiceProvider>(); var configuration = services.GetRequiredService <IConfiguration>(); UserRoleSeed.createRoles(serviceProvider, configuration).Wait(); } catch (Exception exception) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(exception, "An error occurred while creating roles"); } } host.Run(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationDbContext>(); UserRoleSeed.InitializeAsync(context, services).Wait(); } catch (Exception ex) { // var logger = services.GetRequiredService<ILogger<Program>>(); // logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var serviceProvider = scope.ServiceProvider; try { var roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >(); UserRoleSeed.Seed(roleManager); var userManager = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >(); UserRoleSeed.SeedUser(userManager); var school = serviceProvider.GetRequiredService <SchoolContext>(); UserRoleSeed.SeedToDb(school, userManager); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("OtherText"); } } host.Run(); }
protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); #region ApplicationUser builder.Entity <ApplicationUser>(b => { b.HasMany(x => x.UserRoles).WithOne().HasForeignKey(ur => ur.UserId).IsRequired(); b.HasMany(t => t.TreatmentHistories).WithOne(th => th.User).HasForeignKey(th => th.UserId).IsRequired(); b.HasMany(t => t.Schedule).WithOne(s => s.User).HasForeignKey(s => s.UserId).IsRequired(); b.HasMany(t => t.Comments).WithOne(c => c.User).HasForeignKey(th => th.UserId); }); builder.Entity <ApplicationRole>(b => { b.HasMany(ur => ur.UserRoles).WithOne().HasForeignKey(ur => ur.RoleId).IsRequired(); }); builder.Entity <ApplicationUserRole>(b => { b.HasOne(ur => ur.Role).WithMany(r => r.UserRoles).HasForeignKey(ur => ur.RoleId); b.HasOne(ur => ur.User).WithMany(r => r.UserRoles).HasForeignKey(ur => ur.UserId); }); #endregion #region Affiliate builder.Entity <Affiliate>(b => { b.HasMany(u => u.Users).WithOne(a => a.Affiliate); b.HasOne(a => a.Address).WithOne(a => a.Affiliate).HasForeignKey <Address>(a => a.AffiliateId); b.HasMany(t => t.TreatmentHistories).WithOne(a => a.Affiliate); }); #endregion #region Patient builder.Entity <Patient>(b => { b.HasOne(p => p.MedicalChart).WithOne(mc => mc.Patient).HasForeignKey <MedicalChart>(mc => mc.PatientId); b.HasMany(p => p.Schedule).WithOne(c => c.Patient).HasForeignKey(th => th.PatientId); }); #endregion #region MedicalChart builder.Entity <MedicalChart>(b => { b.HasMany(t => t.Teeth).WithOne(mc => mc.MedicalChart); b.HasMany(t => t.Allergies).WithOne(mc => mc.MedicalChart); b.HasMany(t => t.Files).WithOne(mc => mc.MedicalChart); b.HasMany(t => t.TreatmentHistories).WithOne(mc => mc.MedicalChart); }); #endregion #region ToothDisease builder.Entity <ToothDisease>().HasKey(td => new { td.DiseaseId, td.ToothId }); builder.Entity <ToothDisease>().HasOne(td => td.Disease).WithMany(d => d.ToothDiseases).HasForeignKey(td => td.DiseaseId); builder.Entity <ToothDisease>().HasOne(td => td.Tooth).WithMany(d => d.ToothDiseases).HasForeignKey(td => td.ToothId); #endregion #region Treatment builder.Entity <Treatment>(b => { b.HasMany(t => t.TreatmentHistories).WithOne(th => th.Treatment); }); #endregion #region Tooth builder.Entity <Tooth>(b => { b.HasMany(t => t.Comments).WithOne(c => c.Tooth); b.HasMany(t => t.TreatmentHistories).WithOne(c => c.Tooth); }); #endregion #region Seeds RoleSeeder.Seed(builder); AffiliateSeeder.Seed(builder); UserSeeder.Seed(builder); UserRoleSeed.Seed(builder); #endregion }