Exemplo n.º 1
0
 public ActionResult TestDatabaseConnection(ViewModels.InitialSetup DatabaseSettings)
 {
     try
     {
         var errorsList = PreValidateDatabaseSettings(DatabaseSettings);
         if (errorsList.Count > 0)
         {
             return(Json(new
             {
                 IsSuccessful = false,
                 ErrorMessage = String.Join("\r\n", errorsList.ToArray())
             }));
         }
         var    connectionStrigBuilder = BaseController.BuildConnectionStringBuilder(DatabaseSettings);
         string errors            = string.Empty;
         bool   isValidConnection = IsValidConnectionString(connectionStrigBuilder.ConnectionString, out errors);
         if (isValidConnection)
         {
             return(Json(new { IsSuccessful = true }));
         }
         else
         {
             return(Json(new { IsSuccessful = false, ErrorMessage = errors }));
         }
     }
     catch (Exception ex)
     {
         return(Json(new { IsSuccessful = false, ErrorMessage = ex.Message }));
     }
 }
Exemplo n.º 2
0
 // GET: Admin
 public ActionResult InitialSetup()
 {
     if (Utils.PreConfigurationHelper.IsInitialSetup(HttpContext))
     {
         StringBuilder strMessage = new StringBuilder();
         strMessage.AppendLine("Please set the initial configuration to access the database");
         var adminUser = PreConfigurationHelper.GetLocalAdminInfo(HttpContext);
         {
             if (adminUser == null)
             {
                 adminUser          = new LocalAdminInfo();
                 adminUser.Username = "******";
             }
             PreConfigurationHelper.SaveAdminUser(adminUser, HttpContext);
         }
         ViewBag.Message = strMessage.ToString();
     }
     else
     {
         if (!HttpContext.User.Identity
             .IsAuthenticated)
         {
             var routeUrl = Url.RouteUrl("InitialSetupRoute");
             return(RedirectToAction(controllerName: "Account", actionName: "Login", routeValues: new { ReturnUrl = routeUrl }));
         }
     }
     ViewModels.InitialSetup model = new ViewModels.InitialSetup();
     model.IntegratedSecuritySSPI = true;
     return(View(model));
 }
Exemplo n.º 3
0
        protected bool SaveConnectionString(ViewModels.InitialSetup model, out string errors)
        {
            bool succeeded = false;

            errors = string.Empty;
            System.Data.SqlClient.SqlConnectionStringBuilder strCSB = BuildConnectionStringBuilder(model);
            try
            {
                bool isValidConnectionString = IsValidConnectionString(strCSB.ConnectionString, out errors);
                if (isValidConnectionString)
                {
                    var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
                    configuration.ConnectionStrings.ConnectionStrings.Remove("DefaultConnection");
                    configuration.ConnectionStrings.ConnectionStrings.Add(
                        new System.Configuration.ConnectionStringSettings("DefaultConnection", strCSB.ConnectionString, "System.Data.SqlClient"));
                    configuration.Save(System.Configuration.ConfigurationSaveMode.Modified);
                    succeeded = true;
                }
                else
                {
                    succeeded = false;
                }
            }
            catch (Exception ex)
            {
                ViewBag.Error = "Unable to setup database configuration. Error: " + ex.ToString();
                succeeded     = false;
            }
            return(succeeded);
        }
Exemplo n.º 4
0
 public ActionResult InitialSetup(ViewModels.InitialSetup model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     else
     {
         var adminUser = PreConfigurationHelper.GetLocalAdminInfo(HttpContext);
         if (adminUser != null)
         {
             string errors = string.Empty;
             if (SaveConnectionString(model, out errors))
             {
                 adminUser.InitialDatabaseConfigured = true;
                 PreConfigurationHelper.SaveAdminUser(adminUser, HttpContext);
                 return(RedirectToAction(actionName: "Login", controllerName: "Account"));
             }
             else
             {
                 if (!string.IsNullOrWhiteSpace(errors))
                 {
                     ViewBag.Error = errors;
                 }
                 return(View(model));
             }
         }
         else
         {
             ViewBag.Error = "There is no admin user in the local database, please create it";
             return(View(model));
         }
     }
 }