public SimpleMembershipInitializer() { System.Data.Entity.Database.SetInitializer<CrisisCheckin>(null); try { using (var context = new CrisisCheckin()) { if (!context.Database.Exists()) { // Create the SimpleMembership database without Entity Framework migration schema ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); } } if (!WebSecurity.Initialized) { WebSecurity.InitializeDatabaseConnection("CrisisCheckin", "User", "Id", "UserName", autoCreateTables: true); } } catch (Exception ex) { throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex); } }
public static void Initialize() { using (var db = new CrisisCheckin()) { if (!db.Database.CompatibleWithModel(false)) { Database.SetInitializer<CrisisCheckin>(new MigrateDatabaseToLatestVersion<CrisisCheckin, Models.Migrations.Configuration>()); db.Database.Initialize(false); } Models.Migrations.Configuration.SeedIfNotEmpty(db); } }
public void SetUp() { AppDomain.CurrentDomain.SetData("DataDirectory", Directory.GetCurrentDirectory()); using (var dbContext = new CrisisCheckin()) { dbContext.Database.Delete(); new MigrateDatabaseToLatestVersion<CrisisCheckin, CrisisCheckinConfiguration>() .InitializeDatabase(dbContext); Seed(dbContext); } }
static void Seed(CrisisCheckin dbContext) { dbContext.Clusters.AddOrUpdate( c => c.Name, new Cluster { Name = "Agriculture Cluster" }, new Cluster { Name = "Camp Coordination and Management Cluster" }, new Cluster { Name = "Early Recovery Cluster" }, new Cluster { Name = "Emergency Shelter Cluster" }, new Cluster { Name = "Emergency Telecommunications Cluster" }, new Cluster { Name = "Food Cluster" }, new Cluster { Name = "Health Cluster" }, new Cluster { Name = "Logistics Cluster" }, new Cluster { Name = "Nutrition Cluster" }, new Cluster { Name = "Protection Cluster" }, new Cluster { Name = "Water and Sanitation Cluster" } ); dbContext.SaveChanges(); }
public static void InitializeCrisisCheckinAndMembershipData() { var migrateOnStartup = false; if (!bool.TryParse(ConfigurationManager.AppSettings["MigrateDbToLatestOnStartup"], out migrateOnStartup)) { migrateOnStartup = false; } if (migrateOnStartup) { Database.SetInitializer<CrisisCheckin>(new MigrateDatabaseToLatestVersion<CrisisCheckin, Models.Migrations.CrisisCheckinConfiguration>()); } else { Database.SetInitializer<CrisisCheckin>(null); } //Users are created via membership so never ever do initialization Database.SetInitializer<CrisisCheckinMembership>(null); using (var db = new CrisisCheckin()) { db.Database.CreateIfNotExists(); if (migrateOnStartup) { var configuration = new CrisisCheckinConfiguration(); var migrator = new DbMigrator(configuration); migrator.Update(); } AuthConfig.Register(); AuthConfig.VerifyRolesAndDefaultAdminAccount(); using (var mdb = new CrisisCheckinMembership()) { SeedIfNotEmpty(db, mdb); } } }
public DataService(CrisisCheckin ctx, CrisisCheckinMembership mctx) { context = ctx; membership_context = mctx; }
public DataService(CrisisCheckin ctx) { context = ctx; }
public PersonController(CrisisCheckin dbContext, IWebSecurityWrapper webSecurity) { DbContext = dbContext; WebSecurity = webSecurity; }
public static void SeedIfNotEmpty(CrisisCheckin context, CrisisCheckinMembership membership_context) // Not overriding DbMigrationsConfiguration<T>.Seed, since it doesn't seem to always get called when it should. { // We want to call this method even when the database updates aren't necessary. That's // because VS 2013 tooling automatically creates the DB when the app starts. Therefore, // this code only executes when the clusters table is empty. That's a good proxy for a // clean database with no data. if (context.Clusters.Any()) return; context.ClusterGroups.AddOrUpdate(g => g.Name, new ClusterGroup { Name = "UN Clusters", Description = "The UN Cluster list." }); context.SaveChanges(); var clusterGroup = context.ClusterGroups.First(); context.Clusters.AddOrUpdate( c => c.Name, new Cluster { Name = "Agriculture Cluster", ClusterGroupId = clusterGroup.Id }, new Cluster { Name = "Camp Coordination and Management Cluster", ClusterGroupId = clusterGroup.Id }, new Cluster { Name = "Early Recovery Cluster", ClusterGroupId = clusterGroup.Id }, new Cluster { Name = "Emergency Shelter Cluster", ClusterGroupId = clusterGroup.Id }, new Cluster { Name = "Emergency Telecommunications Cluster", ClusterGroupId = clusterGroup.Id }, new Cluster { Name = "Food Cluster", ClusterGroupId = clusterGroup.Id }, new Cluster { Name = "Health Cluster", ClusterGroupId = clusterGroup.Id }, new Cluster { Name = "Logistics Cluster", ClusterGroupId = clusterGroup.Id }, new Cluster { Name = "Nutrition Cluster", ClusterGroupId = clusterGroup.Id }, new Cluster { Name = "Protection Cluster", ClusterGroupId = clusterGroup.Id }, new Cluster { Name = "Water and Sanitation Cluster", ClusterGroupId = clusterGroup.Id } ); context.SaveChanges(); var vtype = context.VolunteerTypes.First(vt => vt.Name == VolunteerType.VOLUNTEERTYPE_ONSITE); var firstCluster = context.Clusters.FirstOrDefault(); context.Persons.AddOrUpdate( p => p.FirstName, new Person { FirstName = "Bob", Commitments = new Commitment[] { new Commitment { StartDate = new DateTime(2014, 1, 1), EndDate = new DateTime(2014, 2, 1), Disaster = new Disaster { Name = "Hurricane", IsActive = true }, VolunteerType = vtype, Cluster = firstCluster } } }); // Set up automated test user var testUser = membership_context.Users.FirstOrDefault(u => u.UserName == Constants.DefaultTestUserName); if (testUser != null) { if (context.Persons.FirstOrDefault(p => p.UserId == testUser.Id) == null) { context.Persons.Add(new Person { UserId = testUser.Id, FirstName = "Test", LastName = "User", Email = "*****@*****.**", Commitments = new Commitment[] { new Commitment { StartDate = new DateTime(DateTime.Now.Year, 1, 1), EndDate = new DateTime(DateTime.Now.Year, 2, 1), Disaster = new Disaster { Name = "Test Disaster", IsActive = true }, VolunteerType = vtype, Cluster = firstCluster } }, OrganizationId = 1, Organization = new Organization { OrganizationName = "Humanitarian Toolbox", OrganizationId = 1, Type = OrganizationTypeEnum.NonProfit, Location = new Address { AddressLine1 = "HT AddressLine 1", AddressLine2 = "HT Address Line 2", AddressLine3 = "HT Address Line 3", BuildingName = "HT Building Name", City = "HTCity", Country = "USA", County = "HT County", PostalCode = "12345", State = "HT State" }, Verified = true } }); } } context.SaveChanges(); context.DisasterClusters.Add(new DisasterCluster { DisasterId = 1, ClusterId = 1 }); context.DisasterClusters.Add(new DisasterCluster { DisasterId = 2, ClusterId = 2 }); context.SaveChanges(); }
// Not overriding DbMigrationsConfiguration<T>.Seed, since it doesn't seem to always get called when it should. public static void SeedIfNotEmpty(CrisisCheckin context, CrisisCheckinMembership membership_context) { // We want to call this method even when the database updates aren't necessary. That's // because VS 2013 tooling automatically creates the DB when the app starts. Therefore, // this code only executes when the clusters table is empty. That's a good proxy for a // clean database with no data. if (context.Clusters.Any()) return; context.Clusters.AddOrUpdate( c => c.Name, new Cluster { Name = "Agriculture Cluster" }, new Cluster { Name = "Camp Coordination and Management Cluster" }, new Cluster { Name = "Early Recovery Cluster" }, new Cluster { Name = "Emergency Shelter Cluster" }, new Cluster { Name = "Emergency Telecommunications Cluster" }, new Cluster { Name = "Food Cluster" }, new Cluster { Name = "Health Cluster" }, new Cluster { Name = "Logistics Cluster" }, new Cluster { Name = "Nutrition Cluster" }, new Cluster { Name = "Protection Cluster" }, new Cluster { Name = "Water and Sanitation Cluster" } ); context.SaveChanges(); var vtype = context.VolunteerTypes.First(vt => vt.Name == VolunteerType.VOLUNTEERTYPE_ONSITE); context.Persons.AddOrUpdate( p => p.FirstName, new Person { FirstName = "Bob", Commitments = new Commitment[] { new Commitment { StartDate = new DateTime(2014, 1, 1), EndDate = new DateTime(2014, 2, 1), Disaster = new Disaster { Name = "Hurricane", IsActive = true }, VolunteerType = vtype } } }); // Set up automated test user var testUser = membership_context.Users.FirstOrDefault(u => u.UserName == Constants.DefaultTestUserName); if (testUser != null) { if (context.Persons.FirstOrDefault(p => p.UserId == testUser.Id) == null) { context.Persons.Add(new Person { UserId = testUser.Id, FirstName = "Test", LastName = "User", Email = "*****@*****.**", Commitments = new Commitment[] { new Commitment { StartDate = new DateTime(DateTime.Now.Year, 1, 1), EndDate = new DateTime(DateTime.Now.Year, 2, 1), Disaster = new Disaster { Name = "Test Disaster", IsActive = true }, VolunteerType = vtype } } }); } } context.SaveChanges(); context.DisasterClusters.Add(new DisasterCluster { DisasterId = 1, ClusterId = 1 }); context.DisasterClusters.Add(new DisasterCluster { DisasterId = 2, ClusterId = 2 }); context.SaveChanges(); }