Esempio n. 1
0
        private static void InitializeAndSeedDb()
        {
            try
            {
                bool isDatabaseCreate   = Convert.ToBoolean(_configuration["AppConfig:IsDatabaseCreate"]);
                bool isMasterDataInsert = Convert.ToBoolean(_configuration["AppConfig:IsMasterDataInsert"]);

                if (isDatabaseCreate == false)
                {
                    using (var context = new AppDbContext())
                    {
                        context.Database.EnsureCreated();

                        if (isMasterDataInsert == false)
                        {
                            //Generate Seed Data
                            if (context.ApplicationSetting.Count() == 0)
                            {
                                AppDbSeed.Seed(context);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args)
                       .ConfigureAppConfiguration((hostContext, builder) =>
            {
                if (hostContext.HostingEnvironment.IsDevelopment())
                {
                    builder.AddUserSecrets <Program>( );
                }
            })
                       .Build( );

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

                try
                {
                    AppDbSeed.SeedSampleData(services);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >( );
                    logger.LogError(ex, "Error while seeding the db.");
                }
            }



            host.Run();
        }
Esempio n. 3
0
 private static void InitializeAndSeedDb()
 {
     try
     {
         using (var context = new AppDbContext())
         {
             context.Database.EnsureCreated();
             //Generate Seed Data
             if (context.AppSetting.Count() == 0)
             {
                 AppDbSeed.Seed(context);
             }
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build( );

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

                try
                {
                    AppDbSeed.SeedSampleData(services);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >( );
                    logger.LogError(ex, "Error while seeding the db.");
                }
            }



            host.Run( );
        }