Esempio n. 1
0
        // 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)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            var connectionString = new SqlConnectionStringBuilder(Configuration["Data:DefaultConnection:ConnectionString"])
            {
                InitialCatalog = "master"
            }.ConnectionString;

            using (var db = new DataConnection(SqlServerTools.GetDataProvider(), connectionString))
            {
                try
                {
                    var sql = "create database [" +
                              new SqlConnectionStringBuilder(Configuration["Data:DefaultConnection:ConnectionString"])
                              .InitialCatalog + "]";
                    db.Execute(sql);
                }
                catch
                {
                    //
                }
            }

            // Try to create tables
            using (var db = new ApplicationDataConnection())
            {
                TryCreateTable <ApplicationUser>(db);
                TryCreateTable <LinqToDB.Identity.IdentityRole>(db);
                TryCreateTable <LinqToDB.Identity.IdentityUserClaim <string> >(db);
                TryCreateTable <LinqToDB.Identity.IdentityRoleClaim <string> >(db);
                TryCreateTable <LinqToDB.Identity.IdentityUserLogin <string> >(db);
                TryCreateTable <LinqToDB.Identity.IdentityUserRole <string> >(db);
                TryCreateTable <LinqToDB.Identity.IdentityUserToken <string> >(db);
            }

            app.UseStaticFiles();

            app.UseAuthentication();
            // To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    "default",
                    "{controller=Home}/{action=Index}/{id?}");
            });
        }
Esempio n. 2
0
 private void TryCreateTable <T>(ApplicationDataConnection db)
     where T : class
 {
     try
     {
         db.CreateTable <T>();
     }
     catch
     {
         //
     }
 }