public ActionResult Create(InstallModel m) { if (m.InstallType == "SCHEMA" || ModelState.IsValid) { // Read embedded create script Stream str = Assembly.GetExecutingAssembly().GetManifestResourceStream("Piranha.Data.Scripts.Create.sql") ; String sql = new StreamReader(str).ReadToEnd() ; str.Close() ; // Read embedded data script str = Assembly.GetExecutingAssembly().GetManifestResourceStream("Piranha.Data.Scripts.Data.sql") ; String data = new StreamReader(str).ReadToEnd() ; str.Close() ; // Split statements and execute string[] stmts = sql.Split(new char[] { ';' }) ; using (IDbTransaction tx = Database.OpenTransaction()) { // Create database from script foreach (string stmt in stmts) { if (!String.IsNullOrEmpty(stmt.Trim())) SysUser.Execute(stmt, tx) ; } tx.Commit() ; } if (m.InstallType.ToUpper() == "FULL") { // Split statements and execute stmts = data.Split(new char[] { ';' }) ; using (IDbTransaction tx = Database.OpenTransaction()) { // Create user SysUser usr = new SysUser() { Login = m.UserLogin, Email = m.UserEmail, GroupId = new Guid("7c536b66-d292-4369-8f37-948b32229b83"), CreatedBy = new Guid("ca19d4e7-92f0-42f6-926a-68413bbdafbc"), UpdatedBy = new Guid("ca19d4e7-92f0-42f6-926a-68413bbdafbc"), Created = DateTime.Now, Updated = DateTime.Now } ; usr.Save(tx) ; // Create user password SysUserPassword pwd = new SysUserPassword() { Id = usr.Id, Password = m.Password, IsNew = false } ; pwd.Save(tx) ; // Create default data foreach (string stmt in stmts) { if (!String.IsNullOrEmpty(stmt.Trim())) SysUser.Execute(stmt, tx) ; } tx.Commit() ; } } return RedirectToAction("index", "account") ; } return Index() ; }
public ActionResult Create(InstallModel m) { if (m.InstallType == "SCHEMA" || ModelState.IsValid) { // Read embedded create script Stream str = Assembly.GetExecutingAssembly().GetManifestResourceStream(Database.ScriptRoot + ".Create.sql"); String sql = new StreamReader(str).ReadToEnd(); str.Close(); // Read embedded data script str = Assembly.GetExecutingAssembly().GetManifestResourceStream(Database.ScriptRoot + ".Data.sql"); String data = new StreamReader(str).ReadToEnd(); str.Close(); // Split statements and execute string[] stmts = sql.Split(new char[] { ';' }); using (IDbTransaction tx = Database.OpenTransaction()) { // Create database from script foreach (string stmt in stmts) { if (!String.IsNullOrEmpty(stmt.Trim())) { SysUser.Execute(stmt, tx); } } tx.Commit(); } if (m.InstallType.ToUpper() == "FULL") { // Split statements and execute stmts = data.Split(new char[] { ';' }); using (IDbTransaction tx = Database.OpenTransaction()) { // Create user SysUser usr = new SysUser() { Login = m.UserLogin, Email = m.UserEmail, GroupId = new Guid("7c536b66-d292-4369-8f37-948b32229b83"), CreatedBy = new Guid("ca19d4e7-92f0-42f6-926a-68413bbdafbc"), UpdatedBy = new Guid("ca19d4e7-92f0-42f6-926a-68413bbdafbc"), Created = DateTime.Now, Updated = DateTime.Now }; usr.Save(tx); // Create user password SysUserPassword pwd = new SysUserPassword() { Id = usr.Id, Password = m.Password, IsNew = false }; pwd.Save(tx); // Create default data foreach (string stmt in stmts) { if (!String.IsNullOrEmpty(stmt.Trim())) { SysUser.Execute(stmt, tx); } } tx.Commit(); } } return(RedirectToAction("index", "account")); } return(Index()); }
public ActionResult Create(InstallModel m) { if (ModelState.IsValid) { Database.Install(m.UserLogin, m.Password, m.UserEmail); return RedirectToAction("index", "account") ; } return Index() ; }