Ejemplo n.º 1
0
        public async Task <IdentityResult> DeleteAsync(ApplicationRole role, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var adapter = new DataAccessAdapter())
            {
                var  roleToDelete = new AspNetRoleEntity(role.Id);
                bool deleted      = await adapter.DeleteEntityAsync(roleToDelete, cancellationToken);

                if (!deleted)
                {
                    return(IdentityResult.Failed(new IdentityError {
                        Description = $"Could not delete role {role.Name}."
                    }));
                }
            }

            return(IdentityResult.Success);
        }
Ejemplo n.º 2
0
        public async Task <IdentityResult> CreateAsync(ApplicationRole role, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var adapter = new DataAccessAdapter())
            {
                AspNetRoleEntity roleEntity = new AspNetRoleEntity();
                roleEntity.Id               = role.Id;
                roleEntity.Name             = role.Name;
                roleEntity.NormalizedName   = role.Name.ToUpper();
                roleEntity.ConcurrencyStamp = role.ConcurrencyStamp;

                bool saved = await adapter.SaveEntityAsync(roleEntity, cancellationToken);

                if (!saved)
                {
                    return(IdentityResult.Failed(new IdentityError {
                        Description = $"Could not insert role {role.Name}."
                    }));
                }
            }

            return(IdentityResult.Success);
        }