Example #1
0
 public SiteQueries(CoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Example #2
0
 public GeoQueries(CoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Example #3
0
 public UserQueries(CoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
 public UserCommands(CoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Example #5
0
 public SiteCommands(CoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Example #6
0
 public SiteCommands(CoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Example #7
0
 public UserQueries(CoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
 public GeoCommands(CoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Example #9
0
        private static async Task EnsureData(
            CoreDbContext db
            )
        {
            int rowsAffected = 0;


            int count = await db.Countries.CountAsync<GeoCountry>();
            if(count == 0)
            {
                foreach(GeoCountry c in InitialData.BuildCountryList())
                {
                    db.Countries.Add(c);
                }

                rowsAffected = await db.SaveChangesAsync();
            }
            
            count = await db.States.CountAsync<GeoZone>();
            if (count == 0)
            {
                foreach (GeoZone c in InitialData.BuildStateList())
                {
                    db.States.Add(c);
                }

                rowsAffected = await db.SaveChangesAsync();
            }
 
            count = await db.Sites.CountAsync<SiteSettings>();
            SiteSettings newSite = null;
            if (count == 0)
            {
                // create first site
                newSite = InitialData.BuildInitialSite();
                
                db.Sites.Add(newSite);
                
                rowsAffected = await db.SaveChangesAsync();
                   
            }

            // ensure roles
            count = await db.Roles.CountAsync<SiteRole>();
            if (count == 0)
            {
                var site = newSite;
                if(site == null)
                {
                    site = await db.Sites.SingleOrDefaultAsync<SiteSettings>(
                        s => s.Id != Guid.Empty && s.IsServerAdminSite == true);
                }
                

                if(site != null)
                {
                    var adminRole = InitialData.BuildAdminRole();
                    adminRole.SiteId = site.Id;
                    db.Roles.Add(adminRole);

                    var roleAdminRole = InitialData.BuildRoleAdminRole();
                    roleAdminRole.SiteId = site.Id;
                    db.Roles.Add(roleAdminRole);

                    var contentAdminRole = InitialData.BuildContentAdminsRole();
                    contentAdminRole.SiteId = site.Id;
                    db.Roles.Add(contentAdminRole);

                    var authenticatedUserRole = InitialData.BuildAuthenticatedRole();
                    authenticatedUserRole.SiteId = site.Id;
                    db.Roles.Add(authenticatedUserRole);
                    
                    rowsAffected = await db.SaveChangesAsync();
                    
                }

            }

            // ensure admin user
            count = await db.Users.CountAsync<SiteUser>();
            
            if (count == 0)
            {
                SiteSettings site = await db.Sites.SingleOrDefaultAsync<SiteSettings>(
                    s => s.Id != Guid.Empty && s.IsServerAdminSite == true);
                    
                if (site != null)
                {
                    var role = await db.Roles.SingleOrDefaultAsync(
                            x => x.SiteId == site.Id && x.NormalizedRoleName == "Administrators".ToUpperInvariant());

                    if(role != null)
                    {
                        var adminUser = InitialData.BuildInitialAdmin();
                        adminUser.SiteId = site.Id;
                        db.Users.Add(adminUser);
                        
                        rowsAffected = await db.SaveChangesAsync();
                        
                        if(rowsAffected > 0 && adminUser.Id != Guid.Empty)
                        {
                            var ur = new UserRole();
                            ur.RoleId = role.Id;
                            ur.UserId = adminUser.Id;
                            db.UserRoles.Add(ur);
                            await db.SaveChangesAsync();

                            role = await db.Roles.SingleOrDefaultAsync(
                                 x => x.SiteId == site.Id && x.NormalizedRoleName == "Authenticated Users".ToUpperInvariant());

                            if(role != null)
                            {
                                ur = new UserRole();
                                ur.RoleId = role.Id;
                                ur.UserId = adminUser.Id;
                                db.UserRoles.Add(ur);
                                await db.SaveChangesAsync();
                            }
                            

                        }
                    }

                }

            }
            
        }
Example #10
0
 public GeoCommands(CoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Example #11
0
 public SiteQueries(CoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }