internal EfCoreRepositoryBase(
     ICoreDbContext contextFactory,
     ICachingStrategy <T, TKey> cachingStrategy = null)
     : base(cachingStrategy)
 {
     this.context = contextFactory;
     DbSet        = context.Set <T>();
 }
Exemplo n.º 2
0
 public UnitOfWork(ICoreDbContext context)
 {
     this.context = context;
     if (this.context != null)
     {
         this.context.ChangeTracker.QueryTrackingBehavior    = QueryTrackingBehavior.NoTracking;
         this.context.ChangeTracker.AutoDetectChangesEnabled = false;
     }
 }
Exemplo n.º 3
0
 public UnitOfWork(IDbContextFactory dbContextFactory)
 {
     context = dbContextFactory.Create();
     if (context != null)
     {
         context.ChangeTracker.AutoDetectChangesEnabled = false;
         context.ChangeTracker.QueryTrackingBehavior    = QueryTrackingBehavior.NoTracking;
     }
 }
Exemplo n.º 4
0
        private void DeleteUserRoles(
            Guid siteId,
            Guid userId,
            ICoreDbContext dbContext)
        {
            var query = from x in dbContext.UserRoles
                        where x.UserId == userId
                        select x;

            dbContext.UserRoles.RemoveRange(query);
        }
Exemplo n.º 5
0
        private void DeleteClaimsByUser(
            Guid siteId,
            Guid userId,
            ICoreDbContext dbContext)
        {
            var query = from x in dbContext.UserClaims
                        where (
                (siteId == Guid.Empty || x.SiteId == siteId) &&
                x.UserId == userId
                )
                        select x;

            dbContext.UserClaims.RemoveRange(query);
        }
Exemplo n.º 6
0
        private void DeleteTokensByUser(
            Guid siteId,
            Guid userId,
            ICoreDbContext dbContext)
        {
            var query = from l in dbContext.UserTokens
                        where (
                l.SiteId == siteId &&
                l.UserId == userId
                )
                        select l;

            dbContext.UserTokens.RemoveRange(query);
        }
Exemplo n.º 7
0
 public SiteCommands(ICoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Exemplo n.º 8
0
        private static async Task EnsureData(
            ICoreDbContext 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.FirstOrDefaultAsync <SiteSettings>(
                    s => s.Id != Guid.Empty && s.IsServerAdminSite == true);

                if (site != null)
                {
                    var role = await db.Roles.FirstOrDefaultAsync(
                        x => x.SiteId == site.Id && x.NormalizedRoleName == "ADMINISTRATORS");

                    if (role != null)
                    {
                        var adminUser = InitialData.BuildInitialAdmin();
                        adminUser.SiteId         = site.Id;
                        adminUser.Id             = Guid.NewGuid();
                        adminUser.CanAutoLockout = false;
                        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();
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
 public GeoCommands(ICoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Exemplo n.º 10
0
 public SiteQueries(ICoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Exemplo n.º 11
0
 public UserCommands(ICoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Exemplo n.º 12
0
 public SiteQueries(ICoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Exemplo n.º 13
0
 public UnitOfWork(ICoreDbContext db)
 {
     this.db = db;
 }
Exemplo n.º 14
0
 public GeoQueries(ICoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Exemplo n.º 15
0
 public SystemRepository(ICoreDbContext coreDbContext)
 {
     _coreDbContext = coreDbContext;
 }
Exemplo n.º 16
0
 public UserCommands(ICoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Exemplo n.º 17
0
 public UserQueries(ICoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Exemplo n.º 18
0
 public GeoCommands(ICoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Exemplo n.º 19
0
 public UserQueries(ICoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Exemplo n.º 20
0
 public Repository <T> SetContext(ICoreDbContext db)
 {
     this.db = db;
     return(this);
 }
Exemplo n.º 21
0
 public UserRepository(ICoreDbContext coreDbContext)
 {
     _coreDbContext = coreDbContext;
 }
 public TestEfCoreRepository(ICoreDbContext dbContext, ICachingStrategy <T, TKey> cachingStrategy = null)
     : base(dbContext, cachingStrategy)
 {
 }
Exemplo n.º 23
0
 public LoginQueryHandler(ICoreDbContext dbContext, IUserIdentityService identityService, ICoreLogger logger)
 {
     _dbContext       = dbContext;
     _identityService = identityService;
     _logger          = logger;
 }
Exemplo n.º 24
0
 public UnitOfWork(ICoreDbContext context, IServiceProvider provider)
 {
     this.context  = context;
     this.provider = provider;
     cache         = new Dictionary <Type, object>();
 }
Exemplo n.º 25
0
 public GeoQueries(ICoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Exemplo n.º 26
0
 public EfCoreRepository(ICoreDbContext contextFactory, ICompoundKeyCachingStrategy <T, TKey, TKey2, TKey3> cachingStrategy = null)
     : base(contextFactory, cachingStrategy)
 {
 }
Exemplo n.º 27
0
 public SiteCommands(ICoreDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Exemplo n.º 28
0
        private static async Task EnsureData(
            ICoreDbContext 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.FirstOrDefaultAsync<SiteSettings>(
                    s => s.Id != Guid.Empty && s.IsServerAdminSite == true);
                    
                if (site != null)
                {
                    var role = await db.Roles.FirstOrDefaultAsync(
                            x => x.SiteId == site.Id && x.NormalizedRoleName == "ADMINISTRATORS");

                    if(role != null)
                    {
                        var adminUser = InitialData.BuildInitialAdmin();
                        adminUser.SiteId = site.Id;
                        adminUser.Id = Guid.NewGuid();
                        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();
                            }
                            

                        }
                    }

                }

            }
            
        }