public ActionResult Index(InstallModel model)
        {
            if (!string.IsNullOrEmpty(Common.GetConnectionString()))
                return RedirectToAction("Index", "Home");

            //set page timeout to 5 minutes
            this.Server.ScriptTimeout = 300;
        
            //values
            if (string.IsNullOrEmpty(model.SqlServerName))
                ModelState.AddModelError("", "SQL Server name is required");
            if (string.IsNullOrEmpty(model.SqlDatabaseName))
                ModelState.AddModelError("", "Database name is required");

            //authentication type
            if (model.SqlAuthenticationType.Equals("sqlauthentication", StringComparison.InvariantCultureIgnoreCase))
            {
                //SQL authentication
                if (string.IsNullOrEmpty(model.SqlServerUsername))
                    ModelState.AddModelError("", "SQL username is required");
                if (string.IsNullOrEmpty(model.SqlServerPassword))
                    ModelState.AddModelError("", "SQL password is required");
                if (string.IsNullOrEmpty(model.SqlServerConfirmPassword))
                    ModelState.AddModelError("", "SQL password confirm is required");

                if (!string.IsNullOrEmpty(model.SqlServerPassword) &&
                    !string.IsNullOrEmpty(model.SqlServerConfirmPassword) &&
                    model.SqlServerPassword != model.SqlServerConfirmPassword)
                {
                    ModelState.AddModelError("", "SQL passwords do not match");
                }
            }

            //Consider granting access rights to the resource to the ASP.NET request identity. 
            //ASP.NET has a base process identity 
            //(typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, 
            //and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating.
            //If the application is impersonating via <identity impersonate="true"/>, 
            //the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

            //validate permissions
            string rootDir = Server.MapPath("~/");
            var dirsToCheck = new List<string>();
            dirsToCheck.Add(rootDir + "Uploads");
            dirsToCheck.Add(rootDir + "App_Data");
            foreach (string dir in dirsToCheck)
            {
                if (!CheckPermissions(dir, false, true, true, true))
                {
                    ModelState.AddModelError("", string.Format("The '{0}' account is not granted with Modify permission on folder '{1}'. Please configure these permissions.", WindowsIdentity.GetCurrent().Name, dir));
                }
            }

            if (ModelState.IsValid)
            {
                try
                {
                    string sqlProviderConnectionString = Common.CreateSqlProviderConnectionString(model.SqlAuthenticationType == "windowsauthentication",
                            model.SqlServerName, model.SqlDatabaseName,
                            model.SqlServerUsername, model.SqlServerPassword);
                    

                    if (model.SqlServerCreateDatabase)
                    {
                        if (!SqlServerDatabaseExists(sqlProviderConnectionString))
                        {
                            //create database
                            var errorCreatingDatabase = CreateDatabase(sqlProviderConnectionString);
                            if (!String.IsNullOrEmpty(errorCreatingDatabase))
                                throw new Exception(errorCreatingDatabase);
                            else
                            {
                                //Database cannot be created sometimes. Weird! Seems to be Entity Framework issue
                                //that's just wait 10 seconds
                                Thread.Sleep(10000);
                            }
                        }
                    }
                    else
                    {
                        //check whether database exists
                        if (!SqlServerDatabaseExists(sqlProviderConnectionString))
                            throw new Exception("Database does not exist or you don't have permissions to connect to it. ");
                    }  

                    //run scripts
                    string result = RunSQLScripts(Server.MapPath("~/Install/CreateDB.sql"), sqlProviderConnectionString);
                    string efConnectionString = Common.CreateEFConnectionString(sqlProviderConnectionString);
                    if (string.IsNullOrEmpty(result))
                    {
                        //save user data
                        //RTSEntities ctx = new DAL.RTSEntities(efConnectionString);
                        Thread.Sleep(4000);                       
                    }
                    else
                    {
                        throw new Exception(result);
                    }

                    //save connection string
                    if (!SaveConnectionString("RTSEntities", efConnectionString))
                    {
                        throw new Exception(HttpUtility.HtmlDecode("The installer couldn't update the web.config file on your server. This may be caused by limited file system permissions. Please open your web.config file manually in Notepad and add the following: &lt;connectionStrings&gt;&lt;add name=\"EntaskerEntities\" connectionString=\"" + sqlProviderConnectionString + "\"/&gt;&lt;/connectionStrings&gt;"));
                    }

                    //restart application so it will pick new connection string
                    //RestartAppDomain();

                    //Redirect to install successful page
                    return RedirectToAction("InstallSuccess", "Install");
                }
                catch (Exception exception)
                {
                    ModelState.AddModelError("", exception.Message);
                }
            }
            return View(model);
        }
        public ActionResult Index()
        {
            if (!string.IsNullOrEmpty(Common.GetConnectionString()))
                return RedirectToAction("Index", "Home");

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

            var model = new InstallModel()
            {
                SqlAuthenticationType = "sqlauthentication",
                SqlServerCreateDatabase = true
            };

            if (!TryWriteWebConfig())
            {
                ModelState.AddModelError("", "The file web.config is read only. Please make it writable.");
            }
            return View(model);
        }