public IActionResult ConnectionTest([FromBody] DbConfigurationModel model) { string connectionString = DataBaseHelper.GetDbConfiguration(model.DataServerName, model.DataAccountName, model.DataPassword, model.DatabaseName, model.CommandTimeOut); bool isConnectionTest = DataBaseHelper.ConnectionTest(connectionString); if (isConnectionTest) { var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", true, reloadOnChange: true); var config = builder.Build(); DataBaseOptions options = new DataBaseOptions() { ConnectionString = connectionString }; IOrganizationBaseRepository organizationBaseRepository = new OrganizationBaseRepository(options); IOrganizationBaseService _organizationBaseService = new Organization.OrganizationBaseService(organizationBaseRepository); List <OrganizationBase> orglist = _organizationBaseService.Query(n => n.Where(x => x.State == 1)); return(new JsonResult(new JsonResultObject() { IsSuccess = true, Content = orglist.SerializeToJson() })); } else { return(new JsonResult(new JsonResultObject() { IsSuccess = false })); } }
public IActionResult Save([FromBody] InitializationModel model) { try { var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", true, reloadOnChange: true); var config = builder.Build(); config["DataBase:ConnectionString"] = DataBaseHelper.GetDbConfiguration(model.DataServerName, model.DataAccountName, model.DataPassword, model.DatabaseName, model.CommandTimeOut); config["Initialization:IsInitialization"] = "true"; WriteJson("DataBase:ConnectionString", config["DataBase:ConnectionString"], config["Initialization:IsInitialization"]); if (model.OrganizationBases != null) { DataBaseOptions options = new DataBaseOptions() { ConnectionString = config["DataBase:ConnectionString"] }; IOrganizationBaseRepository organizationBaseRepository = new OrganizationBaseRepository(options); IOrganizationBaseService _organizationBaseService = new Organization.OrganizationBaseService(organizationBaseRepository); model.OrganizationBases.ForEach(x => { _organizationBaseService.Update(x); }); } return(new JsonResult(new JsonResultObject() { IsSuccess = true })); } catch (Exception ex) { return(new JsonResult(new JsonResultObject() { IsSuccess = false, Content = ex.Message })); } }