Exemplo n.º 1
0
            public async Task <string> Handle(CreateRoleCommand request, CancellationToken cancellationToken)
            {
                ApplicationRole role = ConvertToApplicationRole(request);

                IIdentityResult identityResult = await _roleStorage
                                                 .CreateAsync(role)
                                                 .ConfigureAwait(false);

                identityResult.ThrowIfFailed();

                return(role.Id);
            }
Exemplo n.º 2
0
            public async Task <string> Handle(CreateUserCommand request, CancellationToken cancellationToken)
            {
                ApplicationUser user = ConvertToApplicationUser(request);

                IIdentityResult identityResult = await _userPasswordService
                                                 .CreateUserWithPasswordAsync(user, request.Password)
                                                 .ConfigureAwait(false);

                identityResult.ThrowIfFailed();

                return(user.Id);
            }
Exemplo n.º 3
0
            public async Task <Unit> Handle(DeleteUserCommand request, CancellationToken cancellationToken)
            {
                ApplicationUser userToDelete = await _userStorage.FindByIdAsync(request.UserId)
                                               .ConfigureAwait(false)
                                               ?? throw new NotFoundException(nameof(ApplicationUser), request.UserId);

                IIdentityResult identityResult = await _userStorage.DeleteAsync(userToDelete)
                                                 .ConfigureAwait(false);

                identityResult.ThrowIfFailed();

                return(Unit.Value);
            }
            public async Task <Unit> Handle(ChangeUserPasswordCommand request, CancellationToken cancellationToken)
            {
                ApplicationUser user = await _userStorage.FindByIdAsync(request.UserId)
                                       .ConfigureAwait(false)
                                       ?? throw new NotFoundException(nameof(ApplicationUser), request.UserId);

                IIdentityResult identityResult = await _userPasswordService
                                                 .ChangeUserPasswordAsync(user, request.CurrentPassword, request.NewPassword)
                                                 .ConfigureAwait(false);

                identityResult.ThrowIfFailed();

                return(Unit.Value);
            }
Exemplo n.º 5
0
            public async Task <Unit> Handle(UpdateRoleCommand request, CancellationToken cancellationToken)
            {
                ApplicationRole roleToUpdate = await _roleStorage.FindByIdAsync(request.RoleId)
                                               .ConfigureAwait(false)
                                               ?? throw new NotFoundException(nameof(ApplicationRole), request.RoleId);

                UpdateApplicationRoleProperties(roleToUpdate, request);

                IIdentityResult identityResult = await _roleStorage.UpdateAsync(roleToUpdate)
                                                 .ConfigureAwait(false);

                identityResult.ThrowIfFailed();

                return(Unit.Value);
            }
Exemplo n.º 6
0
            public async Task <Unit> Handle(RevokeTokenCommand request, CancellationToken cancellationToken)
            {
                RefreshToken refreshToken =
                    await _identityDbContext.RefreshTokens
                    .SingleOrDefaultAsync(rf => rf.Token == request.RefreshToken, cancellationToken)
                    .ConfigureAwait(false)
                    ?? throw new NotFoundException(nameof(Identity.Entities.RefreshToken), request.RefreshToken);

                IIdentityResult identityResult = await _jwtService.RevokeRefreshTokenAsync(refreshToken)
                                                 .ConfigureAwait(false);

                identityResult.ThrowIfFailed();

                return(Unit.Value);
            }
Exemplo n.º 7
0
            public async Task <Unit> Handle(DeleteRoleOfUserCommand request, CancellationToken cancellationToken)
            {
                ApplicationUser user = await _userStorage.FindByIdAsync(request.UserId)
                                       .ConfigureAwait(false)
                                       ?? throw new NotFoundException(nameof(ApplicationUser), request.UserId);

                ApplicationRole role = await _roleStorage.FindByIdAsync(request.RoleId)
                                       .ConfigureAwait(false)
                                       ?? throw new NotFoundException(nameof(ApplicationRole), request.RoleId);

                IIdentityResult identityResult = await _userRoleService.RemoveUserFromRoleAsync(user, role)
                                                 .ConfigureAwait(false);

                identityResult.ThrowIfFailed();

                return(Unit.Value);
            }