public static IApplicationBuilder UseFolkeCore(
            this IApplicationBuilder app,
            IFolkeConnection connection,
            IHostingEnvironment env,
            RoleManager <Role> roleManager,
            UserManager <User> userManager,
            ApplicationPartManager applicationPartManager,
            Action <FolkeCoreApplicationOptions> optionsAction)
        {
            app.UseAuthentication();
            app.UseDefaultFiles();
            app.UseStaticFiles();
            app.UseMvc();
            app.UseRequestLocalization();

            var options = new FolkeCoreApplicationOptions();

            optionsAction(options);

            using (var transaction = connection.BeginTransaction())
            {
                connection.UpdateIdentityUserSchema <int, User>();
                connection.UpdateIdentityRoleSchema <int, User>();
                connection.UpdateSchema(typeof(User).GetTypeInfo().Assembly);

                CreateAdministrator(roleManager, userManager, options).GetAwaiter().GetResult();
                transaction.Commit();
            }

            if (env.IsDevelopment())
            {
                CreateTypeScriptServices(applicationPartManager, options.UseKnockout, options.TypeScriptServicesOutDir ?? "src/services");
            }

            return(app);
        }
        private static async Task CreateAdministrator(RoleManager <Role> roleManager, UserManager <User> userManager, FolkeCoreApplicationOptions applicationOptions)
        {
            var administrateur = await roleManager.FindByNameAsync(RoleNames.Administrator);

            if (administrateur == null)
            {
                await roleManager.CreateAsync(new Role { Name = RoleNames.Administrator });
            }

            var users = await userManager.GetUsersInRoleAsync(RoleNames.Administrator);

            if (users.Count == 0)
            {
                var result = await userManager.CreateAsync(new User { UserName = applicationOptions.AdministratorEmail, Email = applicationOptions.AdministratorEmail },
                                                           applicationOptions.AdministratorPassword);

                if (result.Succeeded)
                {
                    var user = await userManager.FindByNameAsync(applicationOptions.AdministratorEmail);

                    await userManager.AddToRoleAsync(user, RoleNames.Administrator);
                }
            }
        }