public ActionResult Index(InstallDatabaseModel model)
        {
            if (DatabaseHelper.DatabaseIsInstalled())
            {
                return(RedirectToRoute("HomePage"));
            }

            //set page timeout to 5 minutes
            this.Server.ScriptTimeout = 300;
            string connectionString;

            if (ModelState.IsValid)
            {
                var webHelper = ContextHelper.Current.Resolve <IUrlHelper>();
                try
                {
                    var settingsManager = new DataSettingsContext();
                    connectionString = "Data Source=" + model.Datasource + ";Initial Catalog=" + model.Database + ";User id=" + model.Username + ";pwd=" + model.Password + "";
                    if (!SqlServerDatabaseExists(connectionString.Trim()))
                    {
                        //create database
                        var collation             = "SQL_Latin1_General_CP1_CI_AS";
                        var errorCreatingDatabase = CreateDatabase(connectionString, collation);
                        if (!String.IsNullOrEmpty(errorCreatingDatabase))
                        {
                            throw new Exception(errorCreatingDatabase);
                        }

                        var dataProvider = "sqlserver";
                        var settings     = new DatabaseSettings
                        {
                            DataProvider         = dataProvider,
                            DataConnectionString = connectionString
                        };
                        settingsManager.SaveSettings(settings);

                        //init data provider
                        var dataProviderInstance = ContextHelper.Current.Resolve <DataManager>().LoadDataProvider();
                        dataProviderInstance.InitDatabase();

                        //now resolve installation service
                        var installationService = ContextHelper.Current.Resolve <IInstallationService>();
                        var school = new School();

                        school.AffiliationNumber  = !String.IsNullOrEmpty(model.School.AffiliationNumber) ? model.School.AffiliationNumber.Trim() : "";
                        school.RegistrationNumber = !String.IsNullOrEmpty(model.School.RegistrationNumber) ? model.School.RegistrationNumber.Trim() : "";

                        school.AcadmicYearName  = model.School.AcadmicYearName;
                        school.City             = !String.IsNullOrEmpty(model.School.City) ? model.School.City.Trim() : "";
                        school.State            = !String.IsNullOrEmpty(model.School.State) ? model.School.State.Trim() : "";
                        school.Country          = !String.IsNullOrEmpty(model.School.Country) ? model.School.Country.Trim() : "";
                        school.Street1          = !String.IsNullOrEmpty(model.School.Street1) ? model.School.Street1.Trim() : "";
                        school.Street2          = !String.IsNullOrEmpty(model.School.Street2) ? model.School.Street2.Trim() : "";
                        school.Landmark         = !String.IsNullOrEmpty(model.School.Landmark) ? model.School.Landmark.Trim() : "";
                        school.ZipCode          = !String.IsNullOrEmpty(model.School.ZipCode) ? model.School.ZipCode.Trim() : "";
                        school.FullName         = !String.IsNullOrEmpty(model.School.FullName) ? model.School.FullName.Trim() : "";
                        school.Longitude        = !String.IsNullOrEmpty(model.School.Longitude) ? model.School.Longitude.Trim() : "";
                        school.Latitude         = !String.IsNullOrEmpty(model.School.Latitude) ? model.School.Latitude.Trim() : "";
                        school.FacebookLink     = !String.IsNullOrEmpty(model.School.FacebookLink) ? model.School.FacebookLink.Trim() : "";
                        school.TweeterLink      = !String.IsNullOrEmpty(model.School.TweeterLink) ? model.School.TweeterLink.Trim() : "";
                        school.InstagramLink    = !String.IsNullOrEmpty(model.School.InstagramLink) ? model.School.InstagramLink.Trim() : "";
                        school.GooglePlusLink   = !String.IsNullOrEmpty(model.School.GooglePlusLink) ? model.School.GooglePlusLink.Trim() : "";
                        school.PInterestLink    = !String.IsNullOrEmpty(model.School.PInterestLink) ? model.School.PInterestLink.Trim() : "";
                        school.SchoolGuid       = new Guid();
                        school.CoverPictureId   = model.School.CoverPictureId;
                        school.ProfilePictureId = model.School.ProfilePictureId;
                        school.Email            = model.School?.Email;

                        installationService.InstallData(model.AdminUsername, model.AdminPassword, school);

                        //reset cache
                        DatabaseHelper.ResetCache();

                        //Redirect to home page
                        return(RedirectToRoute("Root"));
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }

            return(View(model));
        }
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, CMSConfig config)
        {
            //HTTP context and other related stuff
            builder.Register(c =>
                             //register FakeHttpContext when HttpContext is not available
                             HttpContext.Current != null ?
                             (new HttpContextWrapper(HttpContext.Current) as HttpContextBase) :
                             (new AutoHttpContext("~/") as HttpContextBase))
            .As <HttpContextBase>().InstancePerRequest();

            builder.Register(c => c.Resolve <HttpContextBase>().Request)
            .As <HttpRequestBase>()
            .InstancePerLifetimeScope();

            builder.Register(c => c.Resolve <HttpContextBase>().Response)
            .As <HttpResponseBase>()
            .InstancePerRequest();

            builder.Register(c => c.Resolve <HttpContextBase>().Server)
            .As <HttpServerUtilityBase>()
            .InstancePerRequest();

            //builder.Register(c => c.Resolve<HttpContextBase>().Session)
            //    .As<HttpSessionStateBase>()
            //    .InstancePerRequest();

            builder.RegisterType <UrlHelper>().As <IUrlHelper>().InstancePerLifetimeScope();

            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            // Data-Layer
            var dataSettingsManager  = new DataSettingsContext();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            builder.Register(c => dataSettingsManager.LoadSettings()).As <DatabaseSettings>();
            builder.Register(x => new EfDataProviderManager(x.Resolve <DatabaseSettings>())).As <DataManager>().InstancePerDependency();

            builder.Register(x => x.Resolve <DataManager>().LoadDataProvider()).As <IDataProvider>().InstancePerDependency();

            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
                var dataProvider          = efDataProviderManager.LoadDataProvider();
                dataProvider.InitConnectionFactory();

                builder.Register <EF.Data.IDbContext>(c => new EFDbContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
                builder.Register <ITrackerContext>(c => new EFDbContext(dataProviderSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register <EF.Data.IDbContext>(c => new EFDbContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
                builder.Register <ITrackerContext>(c => new EFDbContext(dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();

                //builder.Register<IDbContext>(c => new EFDbContext(dataSettingsManager.LoadSettings().DataConnectionString == null ? "..." : dataSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }

            builder.RegisterGeneric(typeof(EFRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();
            // Register Services
            builder.RegisterType <WebContext>().As <IWebContext>().InstancePerLifetimeScope();
            builder.RegisterType <SocialSettingService>().As <ISocialSettingService>().InstancePerLifetimeScope();
            builder.RegisterSource(new SettingsSource());

            builder.RegisterType <SystemLogService>().As <ISystemLogService>().InstancePerLifetimeScope();
            builder.RegisterType <AuditService>().As <IAuditService>().InstancePerLifetimeScope();
            builder.RegisterType <BlogService>().As <IBlogService>().InstancePerLifetimeScope();
            builder.RegisterType <CommentService>().As <ICommentService>().InstancePerLifetimeScope();
            builder.RegisterType <EventService>().As <IEventService>().InstancePerLifetimeScope();
            builder.RegisterType <PictureService>().As <IPictureService>().InstancePerLifetimeScope();
            builder.RegisterType <ReplyService>().As <IReplyService>().InstancePerLifetimeScope();
            builder.RegisterType <RoleService>().As <IRoleService>().InstancePerLifetimeScope();
            builder.RegisterType <PermissionService>().As <IPermissionService>().InstancePerLifetimeScope();
            builder.RegisterType <UserService>().As <IUserService>().InstancePerLifetimeScope();
            builder.RegisterType <VideoService>().As <IVideoService>().InstancePerLifetimeScope();
            builder.RegisterType <FormsAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <UserContext>().As <IUserContext>().InstancePerLifetimeScope();
            builder.RegisterType <SliderService>().As <ISliderService>().InstancePerLifetimeScope();
            builder.RegisterType <SettingService>().As <ISettingService>().InstancePerLifetimeScope();

            builder.RegisterType <ProductService>().As <IProductService>().InstancePerLifetimeScope();
            builder.RegisterType <FileService>().As <IFileService>().InstancePerLifetimeScope();
            builder.RegisterType <FeedbackService>().As <IFeedbackService>().InstancePerLifetimeScope();
            builder.RegisterType <EmailService>().As <IEmailService>().InstancePerLifetimeScope();
            builder.RegisterType <TemplateService>().As <ITemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomPageService>().As <ICustomPageService>().InstancePerLifetimeScope();
            builder.RegisterType <NewsService>().As <INewsService>().InstancePerLifetimeScope();
            builder.RegisterType <UrlService>().As <IUrlService>().InstancePerLifetimeScope();
            builder.RegisterType <SMSService>().As <ISMSService>().InstancePerLifetimeScope();
            builder.RegisterType <RouteRegistrar>().As <IRouteRegistrar>().InstancePerLifetimeScope();
            builder.RegisterType <SocialModelFactory>().As <ISocialModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <SocialPluginService>().As <ISocialPluginService>().InstancePerLifetimeScope();
            builder.RegisterType <SocialAuthorizer>().As <ISocialAuthorizer>().InstancePerLifetimeScope();
            builder.RegisterType <OpenAuthenticationService>().As <IOpenAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <LicenseService>().As <ILicenseService>().InstancePerLifetimeScope();

            builder.RegisterType <CountryReverseGeocodeService>().As <ICountryReverseGeocodeService>().InstancePerLifetimeScope();
            if (!DatabaseHelper.DatabaseIsInstalled())
            {
                builder.RegisterType <InstallationService>().As <IInstallationService>().InstancePerLifetimeScope();
            }

            builder.RegisterType <CultureHelper>().As <ICultureHelper>().InstancePerLifetimeScope();

            // Scheduled Tasks
            builder.RegisterType <ScheduleTaskService>().As <IScheduleTaskService>().InstancePerLifetimeScope();
            builder.RegisterType <DefaultMachineNameProvider>().As <IMachineNameProvider>().InstancePerLifetimeScope();

            builder.Register(c => c.Resolve <HttpContextBase>().Session).As <HttpSessionStateBase>().InstancePerLifetimeScope();
        }