コード例 #1
0
            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));
            }
コード例 #2
0
        /// <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);
        }
コード例 #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);
            }
コード例 #4
0
            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);
            }
コード例 #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);
            }
コード例 #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);
            }