Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Stripping membership initialization into its own class

  • Loading branch information...
commit a6fb67a8bb384d9f9464d254520912a507aecb46 1 parent 436bf4f
Jess Chadwick jchadwick authored
29 Website/App_Start/DataAccess.cs
View
@@ -1,15 +1,10 @@
using System.Configuration;
using System.Data.Entity;
-using System.Data.SqlClient;
-using System.Linq;
-using System.Web.Management;
-using System.Web.Security;
using Devtalk.EF.CodeFirst;
using Ebuy.DataAccess;
using Ebuy.Website.App_Start;
[assembly: WebActivator.PreApplicationStartMethod(typeof(DataAccess), "InitializeDatabase")]
-[assembly: WebActivator.PostApplicationStartMethod(typeof(DataAccess), "CreateAdminUser")]
namespace Ebuy.Website.App_Start
{
@@ -36,29 +31,5 @@ public static void InitializeDatabase()
context.Database.Initialize(false);
}
}
-
- public static void CreateAdminUser()
- {
- using (var context = new DataContext())
- {
- var admin = new User {
- DisplayName = "Administrator",
- EmailAddress = "admin@ebuy.com",
- Username = "admin",
- };
-
- if (!context.Users.Any(x => x.Key == admin.Key))
- {
- context.Users.Add(admin);
- context.SaveChanges();
-
- var conn = new SqlConnectionStringBuilder(context.Database.Connection.ConnectionString);
- SqlServices.Install(conn.InitialCatalog, SqlFeatures.Membership | SqlFeatures.RoleManager, conn.ConnectionString);
-
- MembershipCreateStatus status;
- Membership.CreateUser(admin.Username, "Password!", admin.EmailAddress, null, null, true, null, out status);
- }
- }
- }
}
}
39 Website/App_Start/InitializeMembership.cs
View
@@ -0,0 +1,39 @@
+using System.Data.SqlClient;
+using System.Linq;
+using System.Web.Management;
+using System.Web.Security;
+using Ebuy.DataAccess;
+using Ebuy.Website.App_Start;
+
+[assembly: WebActivator.PostApplicationStartMethod(typeof(InitializeMembership), "CreateAdminUser")]
+
+namespace Ebuy.Website.App_Start
+{
+ public static class InitializeMembership
+ {
+ public static void CreateAdminUser()
+ {
+ using (var context = new DataContext())
+ {
+ var admin = new User
+ {
+ DisplayName = "Administrator",
+ EmailAddress = "admin@ebuy.com",
+ Username = "admin",
+ };
+
+ if (!context.Users.Any(x => x.Key == admin.Key))
+ {
+ context.Users.Add(admin);
+ context.SaveChanges();
+
+ var conn = new SqlConnectionStringBuilder(context.Database.Connection.ConnectionString);
+ SqlServices.Install(conn.InitialCatalog, SqlFeatures.Membership | SqlFeatures.RoleManager, conn.ConnectionString);
+
+ MembershipCreateStatus status;
+ Membership.CreateUser(admin.Username, "Password!", admin.EmailAddress, null, null, true, null, out status);
+ }
+ }
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.