예제 #1
0
 public static void SeedData(DatabaseContext context, UserManager <Person> userManager, RoleManager <Entities.IdentityRole> roleManager)
 {
     RoleSeed.SeedData(roleManager);
     PersonSeed.SeedData(context, userManager);
     CitySeed.SeedData(context);
     BrandSeed.SeedData(context);
 }
예제 #2
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            // adapted to make sure roles are created first
            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var serviceProvider = services.GetRequiredService <IServiceProvider>();
                    var conf            = services.GetRequiredService <IConfiguration>();

                    try
                    {
                        RoleSeed.CreateRoles(serviceProvider, conf).Wait();
                    }
                    catch (Exception e)
                    {
                        var logger = services.GetRequiredService <ILogger <Program> >();
                        logger.LogError(e.Message, "Error occurred in seeding database.");
                    }
                }
                catch (Exception e)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(e, "An error occurred while creating roles");
                }
            }

            host.Run();
        }
예제 #3
0
        protected override void Seed(AppContext context)
        {
            //  UserSeed.VandGrow(context);
            EstateStatusSeed.VandGrow(context);
            CourseHoldingTypeSeed.VandGrow(context);
            BankSeed.VandGrow(context);
            MaritalStatusSeed.VandGrow(context);
            ReligionSeed.VandGrow(context);
            EducationDegreeSeed.VandGrow(context);
            MilitaryStatusSeed.VandGrow(context);

            ShiftSeed.VandGrow(context);
            RoleSeed.VandGrow(context);
            MenuSeed.VandGrow(context);
            SexSeed.VandGrow(context);
            //ProvinceSeed.VandGrow(context);
            CategorySeed.VandGrow(context);
            SiteSeed.VandGrow(context);

            TeacherSeed.VandGrow(context);
            EducationalCenterUserSeed.VandGrow(context);
            StudentSeed.VandGrow(context);

            MenuSeed.VandGrow(context);
            RecruitmentTypeSeed.VandGrow(context);

            //OrganizationSeed.VandGrow(context);

            //DepartmentTypeSeed.VandGrow(context);
            //SiteSeed.VandGrow(context);
            //LanguageCenterUserRoleSeed.VandGrow(context);
            ClassroomTypeSeed.VandGrow(context);
            //MinistryOfEducationUserSeed.VandGrow(context);
            base.Seed(context);
        }
예제 #4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            var roleSeed = new RoleSeed(Configuration);

            roleSeed.CreateRoles(serviceProvider).Wait();
        }
예제 #5
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope()) {
                var services = scope.ServiceProvider;

                try
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    //
                    //                    StateSeed.Initialize(services);
                    RoleSeed.Initialize(services, logger).Wait();
                    UserSeed.Initialize(services, logger).Wait();

                    EmployeeCvSeed.Initialize(services, logger).Wait();
                    EmployeeCvExternalMaterialSeed.Initialize(services, logger).Wait();
                    EmployeeCvJobHisotriesSeed.Initialize(services, logger).Wait();
                    EmployeeCvSkillSeed.Initialize(services, logger).Wait();
                    EmployeeCvWorkDaySeed.Initialize(services, logger).Wait();

                    EmployerJobProfileSeed.Initialize(services, logger).Wait();
                    EmployerJobSkillSeed.Initialize(services, logger).Wait();
                }
                catch (Exception ex) {
                    services.GetRequiredService <ILogger <Program> >().LogError(ex, "An error occurred while seeding the database");
                    throw;
                }
            }
            host.Run();
//            BuildWebHost(args).Run();
        }
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            RoleSeed.Seed(builder);
            UserSeed.Seed(builder);
            UserRoleSeed.Seed(builder);
        }
예제 #7
0
        public static void Seed(WebAppContext context)
        {
            var db = context.Database.EnsureCreated();

            if (context.User.Any())
            {
                return;
            }
            ApplicationSeed.CreateApplication(context);
            RoleSeed.CreateRole(context);
            UserSeed.CreateUser(context);
        }
예제 #8
0
        static void Main(string[] args)
        {
            var applicationOptionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>();

            applicationOptionsBuilder.UseSqlServer(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=EfTestnn;Integrated Security=True");

            var context = new ApplicationDbContext(applicationOptionsBuilder.Options);

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            RoleSeed.Seed(context);
        }
예제 #9
0
 public static IHost SeedDatabase(this IHost builder)
 {
     using (var scope = builder.Services.CreateScope())
     {
         using (var context = scope.ServiceProvider.GetService <LubricantContext>())
         {
             DaySeed.DaysData(context);
             RoleSeed.RolesData(context);
             UserSeed.UsersData(context);
             context.SaveChanges();
         }
     }
     return(builder);
 }
예제 #10
0
 /// <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);
     }
 }
예제 #11
0
        protected override void Seed(Portal.CMS.Entities.PortalEntityModel context)
        {
            ThemeSeed.Seed(context);
            RoleSeed.Seed(context);
            SettingSeed.Seed(context);
            PostCategorySeed.Seed(context);
            PageSectionTypeSeed.Seed(context);
            PageComponentTypeSeed.Seed(context);
            MediaSeed.Seed(context);
            CopySeed.Seed(context);
            context.SaveChanges();

            MenuSeed.Seed(context);
            PageSeed.Seed(context);
            PostSeed.Seed(context);
        }
예제 #12
0
        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);
        }
예제 #13
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            #region Employee
            modelBuilder.Entity <Employee>()
            .HasOne(a => a.LoginInfo)
            .WithOne(b => b.Employee)
            .HasForeignKey <LoginInfo>(b => b.EmployeeId);

            modelBuilder.Entity <Employee>()
            .HasOne(a => a.AtWork)
            .WithOne(b => b.Employee)
            .HasForeignKey <AtWork>(b => b.EmployeeId);

            modelBuilder.Entity <Employee>()
            .HasData(EmployeeSeed.Seed());

            modelBuilder.Entity <Employee>()
            .HasMany(a => a.LoginsHistory)
            .WithOne(b => b.Employee);
            #endregion

            #region LoginInfo
            modelBuilder.Entity <LoginInfo>()
            .HasIndex(prop => prop.Username)
            .IsUnique();

            modelBuilder.Entity <LoginInfo>()
            .HasData(LoginInfoSeed.Seed());
            #endregion

            #region Role
            modelBuilder.Entity <Role>()
            .HasMany(a => a.Employees)
            .WithOne(b => b.Role);

            modelBuilder.Entity <Role>()
            .HasData(RoleSeed.Seed());
            #endregion

            #region AtWork
            //No seed needed
            #endregion

            #region LoginHistory
            // no seed needed
            #endregion
        }
예제 #14
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              DataSeeder dataSeeder, RoleSeed roleSeed, DbInitializer dbInitializer)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseCors("AllowAll");

            app.UseSignalR(routes =>  // <-- SignalR
            {
                routes.MapHub <PMSHub>("hub");
            });

            app.UseAuthentication();
            app.UseResponseCompression();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
            roleSeed.SeedAsync().Wait();

            dataSeeder.SeedAsync().Wait();

            dbInitializer.Initialize().Wait();
        }
예제 #15
0
        /// <summary>
        /// All seed methods are called from here
        /// </summary>
        /// <returns>Nothing</returns>
        public async Task EnsureSeedData()
        {
            await RoleSeed.SeedDefaultRolesAsync(_roleManager);

            await _db.SeedDefaultUserAsync(_userManager);
        }
예제 #16
0
 protected override void Seed(DataEntities context)
 {
     RoleSeed.SeedRoles(context);
 }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity <Role>(entity => {
                entity.ToTable("Roles", "Security");

                entity.Property(r => r.Name)
                .HasMaxLength(100);

                entity.HasKey(r => r.Name)
                .HasName("PK_Roles");

                entity.HasData(RoleSeed.Roles());

                entity.HasAnnotation("READONLY_ANNOTATION", true);

                entity.HasMany(r => r.UserRoles)
                .WithOne(u => u.Role)
                .HasForeignKey(u => u.RoleId)
                .HasConstraintName("FK_UserRoles_Roles")
                .IsRequired(true);
            });

            modelBuilder.Entity <UserRole>(entity =>
            {
                entity.ToTable("UserRoles", "Security");

                entity.HasIndex(u => u.UserId)
                .HasName("IX_UserRoles_UserId");

                entity.HasIndex(u => u.RoleId)
                .HasName("IX_UserRoles_RoleId");

                entity.Property(u => u.RoleId)
                .HasMaxLength(100);

                entity.Property(u => u.UserId)
                .HasMaxLength(100);

                entity.HasKey(u => new { u.RoleId, u.UserId });
            });

            modelBuilder.Entity <User>(entity =>
            {
                entity.ToTable("Users", "Security");

                entity.HasKey(r => r.Id)
                .HasName("PK_Users");

                entity.Property(r => r.Id)
                .HasMaxLength(100);

                entity.Property(r => r.Username)
                .HasMaxLength(100)
                .IsRequired(true);

                entity.Property(r => r.Email)
                .HasMaxLength(256)
                .IsRequired(true);

                entity.Property(r => r.SecurityStamp)
                .HasMaxLength(100)
                .IsRequired(true);

                entity.Property(r => r.PasswordHash)
                .HasMaxLength(100)
                .IsRequired(true);

                entity.HasIndex(r => r.Username)
                .HasName("IX_Users_Username")
                .IsUnique();

                entity.HasIndex(r => r.Email)
                .HasName("IX_Users_Email")
                .IsUnique();

                entity.HasMany(r => r.UserRoles)
                .WithOne(u => u.User)
                .HasForeignKey(u => u.UserId)
                .HasConstraintName("FK_UserRoles_Users")
                .IsRequired(true);
            });
        }
예제 #18
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserSeed userSeed, RoleSeed roleSeed, LevelSeed levelSeed, EnvironmentSeed environmentSeed, LogSeed logSeed, EventSeed eventSeed)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                userSeed.Populate();
                roleSeed.Populate();
                levelSeed.Populate();
                environmentSeed.Populate();
                logSeed.Populate();
                eventSeed.Populate();
            }

            app.UseSwaggerSetup();

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseCors(c =>
            {
                c.AllowAnyHeader();
                c.AllowAnyMethod();
                c.AllowAnyOrigin();
            });

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }