public async Task <IEnumerable <RoleDto> > Handle(GetListOfUserRolesQuery request,
                                                              CancellationToken cancellationToken)
            {
                ApplicationUser user = await _userStorage.FindByIdAsync(request.UserId)
                                       .ConfigureAwait(false)
                                       ?? throw new NotFoundException(nameof(ApplicationUser), request.UserId);

                return(await _userRoleService.GetUserRoles(user)
                       .AsNoTracking()
                       .ProjectToListAsync <RoleDto>(_mapper.ConfigurationProvider, cancellationToken)
                       .ConfigureAwait(false));
            }
        /// <summary>
        /// Checks if the <paramref name="storage"/> contains an item with the specified <paramref name="id"/>.
        /// </summary>
        public static async Task <bool> Exists <TItem, TItemId>
        (
            this IIdentityStorage <TItem, TItemId> storage,
            TItemId id
        )
            where TItem : class
        {
            TItem item = await storage.FindByIdAsync(id)
                         .ConfigureAwait(false);

            return(item != null);
        }
            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);
            }
            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);
            }
Example #6
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);
            }