Example #1
0
        public void BeforeEachTestAfterBase()
        {
            var roles     = Database.GetCollection <ExtendedIdentityRole>("roles");
            var roleStore = new RoleStore <ExtendedIdentityRole>(roles);

            _manager = new RoleManager <ExtendedIdentityRole>(roleStore);
            _role    = new ExtendedIdentityRole("admin");
        }
Example #2
0
 public void BeforeEachTestAfterBase()
 {
     _Manager = CreateServiceProvider <IdentityUser, ExtendedIdentityRole>()
                .GetService <RoleManager <ExtendedIdentityRole> >();
     _Role = new ExtendedIdentityRole
     {
         Name = "admin"
     };
 }
		public void BeforeEachTestAfterBase()
		{
			var roles = DatabaseNewApi.GetCollection<ExtendedIdentityRole>("roles");
			var roleStore = new RoleStore<ExtendedIdentityRole>(roles);
			_Manager = new RoleManager<ExtendedIdentityRole>(roleStore);
			_Role = new ExtendedIdentityRole
			{
				Name = "admin"
			};
		}
 public void BeforeEachTestAfterBase()
 {
     var context = new IdentityContext(Users, Roles);
     var roleStore = new RoleStore<ExtendedIdentityRole>(context);
     _Manager = new RoleManager<ExtendedIdentityRole>(roleStore);
     _Role = new ExtendedIdentityRole
     {
         Name = "admin"
     };
 }
Example #5
0
        public void BeforeEachTestAfterBase()
        {
            var context   = new IdentityContext(Users, Roles);
            var roleStore = new RoleStore <ExtendedIdentityRole>(context);

            _Manager = new RoleManager <ExtendedIdentityRole>(roleStore);
            _Role    = new ExtendedIdentityRole
            {
                Name = "admin"
            };
        }
Example #6
0
        public void BeforeEachTestAfterBase()
        {
            var roles     = DatabaseNewApi.GetCollection <ExtendedIdentityRole>("roles");
            var roleStore = new RoleStore <ExtendedIdentityRole>(roles);

            _Manager = new RoleManager <ExtendedIdentityRole>(roleStore);
            _Role    = new ExtendedIdentityRole
            {
                Name = "admin"
            };
        }
        public void BeforeEachTestAfterBase()
        {
            var context   = new RolesContext <IdentityRole>(Roles);
            var roleStore = new RoleStore <IdentityRole>(context);

            manager = new RoleManager <IdentityRole>(roleStore);
            role    = new ExtendedIdentityRole
            {
                Name = "admin"
            };
        }
        public override async Task <bool> CreateAsync(ExtendedIdentityRole role)
        {
            const string sql = "INSERT INTO [dbo].[AspNetRoles] " +
                               "VALUES (@Id, @Name, @NormalizedName, @ConcurrencyStamp, @Description);";
            var rowsInserted = await DbConnection.ExecuteAsync(sql, new {
                role.Id,
                role.Name,
                role.NormalizedName,
                role.ConcurrencyStamp,
                role.Description
            });

            return(rowsInserted == 1);
        }
Example #9
0
        public override async Task <IdentityResult> UpdateAsync(ExtendedIdentityRole role, IList <IdentityRoleClaim <string> > claims = null)
        {
            const string updateRoleSql = "UPDATE [dbo].[AspNetRoles] " +
                                         "SET [Name] = @Name, [NormalizedName] = @NormalizedName, [ConcurrencyStamp] = @ConcurrencyStamp, [Description] = @Description " +
                                         "WHERE [Id] = @Id;";

            using (var transaction = DbConnection.BeginTransaction()) {
                await DbConnection.ExecuteAsync(updateRoleSql, new {
                    role.Name,
                    role.NormalizedName,
                    role.ConcurrencyStamp,
                    role.Description,
                    role.Id
                }, transaction);

                if (claims?.Count() > 0)
                {
                    const string deleteClaimsSql = "DELETE " +
                                                   "FROM [dbo].[AspNetRoleClaims] " +
                                                   "WHERE [RoleId] = @RoleId;";
                    await DbConnection.ExecuteAsync(deleteClaimsSql, new {
                        RoleId = role.Id
                    }, transaction);

                    const string insertClaimsSql = "INSERT INTO [dbo].[AspNetRoleClaims] (RoleId, ClaimType, ClaimValue) " +
                                                   "VALUES (@RoleId, @ClaimType, @ClaimValue);";
                    await DbConnection.ExecuteAsync(insertClaimsSql, claims.Select(x => new {
                        RoleId = role.Id,
                        x.ClaimType,
                        x.ClaimValue
                    }), transaction);
                }
                try {
                    transaction.Commit();
                } catch {
                    transaction.Rollback();
                    return(IdentityResult.Failed(new IdentityError {
                        Code = string.Empty,
                        Description = $"Role '{role.Name}' could not be updated."
                    }));
                }
            }
            return(IdentityResult.Success);
        }
Example #10
0
        public override async Task <IdentityResult> CreateAsync(ExtendedIdentityRole role)
        {
            const string sql = "INSERT INTO [dbo].[AspNetRoles] " +
                               "VALUES (@Id, @Name, @NormalizedName, @ConcurrencyStamp, @Description);";
            var rowsInserted = await DbConnection.ExecuteAsync(sql, new {
                role.Id,
                role.Name,
                role.NormalizedName,
                role.ConcurrencyStamp,
                role.Description
            });

            return(rowsInserted == 1
                ? IdentityResult.Success
                : IdentityResult.Failed(new IdentityError {
                Code = string.Empty,
                Description = $"Role '{role.Name}' could not be created."
            }));
        }