コード例 #1
0
        public async Task AddAsync(Role role)
        {
            var entity = _mapper.Map <Role, RoleEntity>(role);

            _dbSet.Add(entity);
            await _context.SaveChangesAsync();

            role.SetRowVersion(entity.RowVersion);
        }
コード例 #2
0
        private static async Task <AccountEntity> InsertAccountEntityAsync(RivaIdentityDbContext context, Guid initialRoleId)
        {
            var accountId     = AuthUserOptions.UserId;
            var accountEntity = new AccountEntity
            {
                Id            = accountId,
                Email         = AuthUserOptions.Email,
                Confirmed     = true,
                PasswordHash  = "PasswordHash",
                SecurityStamp = Guid.NewGuid(),
                Created       = DateTimeOffset.UtcNow,
                Roles         = new List <AccountRoleEntity>
                {
                    new AccountRoleEntity
                    {
                        AccountId = accountId,
                        RoleId    = initialRoleId
                    }
                }
            };

            context.Accounts.Add(accountEntity);
            await context.SaveChangesAsync();

            return(accountEntity);
        }
コード例 #3
0
        private static async Task <AccountEntity> InsertAccountEntityAsync(RivaIdentityDbContext context, string token)
        {
            var accountEntity = new AccountEntity
            {
                Id            = Guid.NewGuid(),
                Email         = "*****@*****.**",
                Confirmed     = false,
                PasswordHash  = "PasswordHash",
                SecurityStamp = Guid.NewGuid(),
                Created       = DateTimeOffset.UtcNow,
                Tokens        = new List <TokenEntity>
                {
                    new TokenEntity
                    {
                        Value   = token,
                        Id      = Guid.NewGuid(),
                        Issued  = DateTimeOffset.UtcNow.AddHours(-1),
                        Expires = DateTimeOffset.UtcNow.AddDays(1),
                        Type    = TokenTypeEnumeration.AccountConfirmation.ConvertToEnum()
                    }
                }
            };

            context.Accounts.Add(accountEntity);
            await context.SaveChangesAsync();

            return(accountEntity);
        }
コード例 #4
0
        public Task AddAsync(Account account)
        {
            var accountEntity = _mapper.Map <Account, AccountEntity>(account);

            foreach (var role in account.Roles)
            {
                accountEntity.Roles.Add(new AccountRoleEntity {
                    AccountId = account.Id, RoleId = role
                });
            }
            foreach (var token in account.Tokens)
            {
                var tokenEntity = _mapper.Map <Token, TokenEntity>(token);
                tokenEntity.AccountId = account.Id;
                accountEntity.Tokens.Add(tokenEntity);
            }
            _dbSet.Add(accountEntity);

            return(_context.SaveChangesAsync());
        }
コード例 #5
0
        private static async Task InsertRoleEntityAsync(RivaIdentityDbContext context)
        {
            var roleEntity = new RoleEntity
            {
                Id         = Guid.NewGuid(),
                Name       = "GetRolesIntegrationTest",
                RowVersion = new byte[] { 1, 2, 4, 8, 16, 64 }
            };

            context.Roles.Add(roleEntity);
            await context.SaveChangesAsync();
        }
コード例 #6
0
        private static async Task <RoleEntity> InsertRoleEntityToUpdateAsync(RivaIdentityDbContext context)
        {
            var roleEntity = new RoleEntity
            {
                Id         = Guid.NewGuid(),
                Name       = "UpdateAccountIntegrationTestRoleToUpdate",
                RowVersion = new byte[] { 1, 2, 4, 8, 16, 32, 64, 128 }
            };

            context.Roles.Add(roleEntity);
            await context.SaveChangesAsync();

            return(roleEntity);
        }
コード例 #7
0
        private static async Task <RoleEntity> InsertRoleEntityAsync(RivaIdentityDbContext context)
        {
            var roleEntity = new RoleEntity
            {
                Id         = Guid.NewGuid(),
                Name       = "DeleteRoleIntegrationTest",
                RowVersion = new byte[] { 0, 0, 0, 0, 0, 0, 70, 81 }
            };

            context.Roles.Add(roleEntity);
            await context.SaveChangesAsync();

            return(roleEntity);
        }
コード例 #8
0
        private static async Task InsertUserRoleEntityIfNotExistsAsync(RivaIdentityDbContext context)
        {
            var roleEntity = await context.Roles.SingleOrDefaultAsync(x => x.Name.Equals(DefaultRoleEnumeration.User.DisplayName));

            if (roleEntity is null)
            {
                roleEntity = new RoleEntity
                {
                    Id         = Guid.NewGuid(),
                    Name       = DefaultRoleEnumeration.User.DisplayName,
                    RowVersion = new byte[] { 1, 2, 4, 8, 16, 32, 64 }
                };
                context.Roles.Add(roleEntity);
                await context.SaveChangesAsync();
            }
        }
コード例 #9
0
        private static async Task <AccountEntity> InsertAccountEntityAsync(RivaIdentityDbContext context)
        {
            var accountEntity = new AccountEntity
            {
                Id            = AuthUserOptions.UserId,
                Email         = AuthUserOptions.Email,
                Confirmed     = true,
                SecurityStamp = Guid.NewGuid(),
                Created       = DateTimeOffset.UtcNow
            };

            context.Accounts.Add(accountEntity);
            await context.SaveChangesAsync();

            return(accountEntity);
        }
コード例 #10
0
        private static async Task <AccountEntity> InsertAccountEntityAsync(RivaIdentityDbContext context)
        {
            var accountEntity = new AccountEntity
            {
                Id            = Guid.NewGuid(),
                Email         = "*****@*****.**",
                Confirmed     = true,
                PasswordHash  = "PasswordHash",
                SecurityStamp = Guid.NewGuid(),
                Created       = DateTimeOffset.UtcNow
            };

            context.Accounts.Add(accountEntity);
            await context.SaveChangesAsync();

            return(accountEntity);
        }
コード例 #11
0
        private static async Task <AccountEntity> InsertAccountEntityAsync(RivaIdentityDbContext context, string password)
        {
            var passwordService = new PasswordService();
            var accountEntity   = new AccountEntity
            {
                Id            = AuthUserOptions.UserId,
                Email         = AuthUserOptions.Email,
                Confirmed     = true,
                PasswordHash  = passwordService.HashPassword(password),
                SecurityStamp = Guid.NewGuid(),
                Created       = DateTimeOffset.UtcNow
            };

            context.Accounts.Add(accountEntity);
            await context.SaveChangesAsync();

            return(accountEntity);
        }
コード例 #12
0
        private static async Task <AccountEntity> InsertAccountEntityAsync(RivaIdentityDbContext context)
        {
            var accountId     = AuthUserOptions.UserId;
            var accountEntity = new AccountEntity
            {
                Id            = AuthUserOptions.UserId,
                Email         = AuthUserOptions.Email,
                Confirmed     = true,
                PasswordHash  = "PasswordHash",
                SecurityStamp = Guid.NewGuid(),
                Created       = DateTimeOffset.UtcNow,
                Roles         = new List <AccountRoleEntity>
                {
                    new AccountRoleEntity
                    {
                        AccountId = accountId,
                        RoleId    = Guid.NewGuid()
                    }
                },
                Tokens = new List <TokenEntity>
                {
                    new TokenEntity
                    {
                        Id        = Guid.NewGuid(),
                        Issued    = DateTimeOffset.UtcNow,
                        Expires   = DateTimeOffset.UtcNow.AddDays(1),
                        Type      = TokenTypeEnumeration.AccountConfirmation.ConvertToEnum(),
                        Value     = "123456",
                        AccountId = accountId
                    }
                }
            };

            context.Accounts.Add(accountEntity);
            await context.SaveChangesAsync();

            return(accountEntity);
        }