//------------------------------------------------------------------------------------------- private void ConfigureDatabase() { using (WeavverEntityContainer data = new WeavverEntityContainer()) { // Run SQL Deploy script string connectionString = ConfigurationManager.ConnectionStrings["WeavverEntityContainer"].ConnectionString; var entityBuilder = new System.Data.EntityClient.EntityConnectionStringBuilder(connectionString); SqlConnection connection = new SqlConnection(entityBuilder.ProviderConnectionString); connection.Open(); string script = System.IO.File.ReadAllText(Server.MapPath(@"\bin\Database.sql")); //data.CreateDatabaseScript(); script = script.Replace("%dalpath%", Server.MapPath(@"\bin\Weavver.DAL.dll")); script = script.Replace("%databasename%", connection.Database); string[] blocks = System.Text.RegularExpressions.Regex.Split(script, "\nGO"); foreach (string block in blocks) { if (block.Trim() != String.Empty) { SqlCommand createDb = new SqlCommand(block, connection); try { createDb.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception("Block: " + block, ex); } } } // CREATE INITIAL DATA Guid orgId = Guid.NewGuid(); Session["SelectedOrganizationId"] = orgId; // deploy first org Weavver.Data.Logistics_Organizations org = new Weavver.Data.Logistics_Organizations(); org.Id = orgId; org.OrganizationId = org.Id; // THIS IS OVERRIDDEN ANYWAY BY AUDITUTILITY AS A SECURITY PRECAUTION org.OrganizationType = "Personal"; org.Name = Organization.Text; org.VanityURL = "default"; org.EIN = ""; org.Founded = DateTime.UtcNow; org.Bio = "This is a sample organization."; org.CreatedAt = DateTime.UtcNow; org.CreatedBy = Guid.Empty; org.UpdatedAt = DateTime.UtcNow; org.UpdatedBy = Guid.Empty; data.Logistics_Organizations.AddObject(org); data.SaveChanges(); Weavver.Data.System_Users user = new Weavver.Data.System_Users(); user.Id = orgId; user.OrganizationId = org.Id; // THIS IS OVERRIDDEN ANYWAY BY AUDITUTILITY AS A SECURITY PRECAUTION user.FirstName = "Enlightened"; user.LastName = "User"; user.Activated = true; user.Locked = false; user.Username = Username.Text; user.Password = Password.Text; user.CreatedAt = DateTime.UtcNow; user.CreatedBy = Guid.Empty; user.UpdatedAt = DateTime.UtcNow; user.UpdatedBy = Guid.Empty; data.System_Users.AddObject(user); data.SaveChanges(); Roles.ApplicationName = orgId.ToString(); string adminuser = user.Username; Roles.CreateRole("Administrators"); Roles.AddUsersToRoles(new string[] { adminuser }, new string[] { "Administrators" }); Roles.CreateRole("Accountants"); Roles.AddUsersToRoles(new string[] { adminuser }, new string[] { "Accountants" }); if (data.SaveChanges() > 0) Response.Redirect("~/install/step2"); } }
//------------------------------------------------------------------------------------------- /// <summary> /// /// </summary> /// <param name="organizationId"></param> /// <returns>This returns the PayeeId on the server.</returns> public string CreatePayeeData(Logistics_Organizations payee) { Billpayment paymentData = GetOFXBillPaymentObject(); PayeeDetail item = new PayeeDetail(); //item.Id = "1234"; item.Account = payee.Id.ToString().Replace("-", ""); item.Name = "John Doe"; item.Addr1 = "Line 1b"; item.Addr2 = "Line 2b"; item.Addr3 = "Line 3"; item.City = "Weavverville"; item.State = "CA"; item.PostalCode = "92832"; item.Country = "USA"; item.Phone = "7148531212"; paymentData.Payee = item; paymentData.AddPayee(); return item.ListId; }
//------------------------------------------------------------------------------------------- private void ConfigureDatabase() { using (WeavverEntityContainer data = new WeavverEntityContainer()) { // Run SQL Deploy script string connectionString = ConfigurationManager.ConnectionStrings["WeavverEntityContainer"].ConnectionString; var entityBuilder = new System.Data.EntityClient.EntityConnectionStringBuilder(connectionString); SqlConnection connection = new SqlConnection(entityBuilder.ProviderConnectionString); connection.Open(); string script = System.IO.File.ReadAllText(Server.MapPath(@"\bin\Database.sql")); //data.CreateDatabaseScript(); script = script.Replace("%dalpath%", Server.MapPath(@"\bin\Weavver.DAL.dll")); script = script.Replace("%databasename%", connection.Database); string[] blocks = System.Text.RegularExpressions.Regex.Split(script, "\nGO"); foreach (string block in blocks) { if (block.Trim() != String.Empty) { SqlCommand createDb = new SqlCommand(block, connection); try { createDb.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception("Block: " + block, ex); } } } // CREATE INITIAL DATA Guid orgId = Guid.NewGuid(); Session["SelectedOrganizationId"] = orgId; // deploy first org Weavver.Data.Logistics_Organizations org = new Weavver.Data.Logistics_Organizations(); org.Id = orgId; org.OrganizationId = org.Id; // THIS IS OVERRIDDEN ANYWAY BY AUDITUTILITY AS A SECURITY PRECAUTION org.OrganizationType = "Personal"; org.Name = Organization.Text; org.VanityURL = "default"; org.EIN = ""; org.Founded = DateTime.UtcNow; org.Bio = "This is a sample organization."; org.CreatedAt = DateTime.UtcNow; org.CreatedBy = Guid.Empty; org.UpdatedAt = DateTime.UtcNow; org.UpdatedBy = Guid.Empty; data.Logistics_Organizations.AddObject(org); data.SaveChanges(); Weavver.Data.System_Users user = new Weavver.Data.System_Users(); user.Id = orgId; user.OrganizationId = org.Id; // THIS IS OVERRIDDEN ANYWAY BY AUDITUTILITY AS A SECURITY PRECAUTION user.FirstName = "Enlightened"; user.LastName = "User"; user.Activated = true; user.Locked = false; user.Username = Username.Text; user.Password = Password.Text; user.CreatedAt = DateTime.UtcNow; user.CreatedBy = Guid.Empty; user.UpdatedAt = DateTime.UtcNow; user.UpdatedBy = Guid.Empty; data.System_Users.AddObject(user); data.SaveChanges(); Roles.ApplicationName = orgId.ToString(); string adminuser = user.Username; Roles.CreateRole("Administrators"); Roles.AddUsersToRoles(new string[] { adminuser }, new string[] { "Administrators" }); Roles.CreateRole("Accountants"); Roles.AddUsersToRoles(new string[] { adminuser }, new string[] { "Accountants" }); if (data.SaveChanges() > 0) { Response.Redirect("~/install/step2"); } } }