Esempio n. 1
0
        public async Task <IActionResult> DeactivateUser([FromBody] UsernameModel deactivateUser)
        {
            _identityService.RetrieveUserAsync().Wait();

            var user = _userManager.Users
                       .Where(UsersFilter.AllUsersFilter(_identityService.User, _identityService.Groups, DATABASE_OPERATION.UPDATE, _serviceProvider))
                       .FirstOrDefault(u => u.UserName == deactivateUser.Username);

            if (user == null)
            {
                return(BadRequest("The user does not exist or you do not have permission to deactivate the user"));
            }

            user.EmailConfirmed = false;
            await _userManager.UpdateAsync(user);

            return(Ok());
        }
Esempio n. 2
0
        public async Task <UserListModel> GetUsers([FromBody] AllUserRequestModel options)
        {
            _identityService.RetrieveUserAsync().Wait();

            var userQuery = _userManager.Users
                            .Where(UsersFilter.AllUsersFilter(_identityService.User, _identityService.Groups, DATABASE_OPERATION.READ, _serviceProvider))
                            .AddConditionalWhereFilter(options.SearchConditions)
                            .AddOrderBys(options.SortConditions);

            return(new UserListModel
            {
                countUsers = await userQuery.CountAsync(),
                Users = userQuery
                        .AddPagination(new Pagination(options.PaginationOptions))
                        .ToList()
                        .Select(u => new UserDto(u))
            });
        }