public async Task <IEnumerable <UserDto> > Handle(GetAllUsersQuery request, CancellationToken cancellationToken)
        {
            IMongoQueryable <UserModel> query = this.context.Users.AsQueryable();

            query = ApplyFilters(request, query);

            var users = await query.ToListAsync(cancellationToken).ConfigureAwait(false);

            return(users.Select(u => CustomMapper.Map <UserDto>(u)));
        }
        public async Task <IEnumerable <UserDto> > Handle(GetAllUsersQuery request, CancellationToken cancellationToken)
        {
            var query = this.context.Users.Where(u => !u.IsDeleted);

            query = ApplyFilters(request, query);

            var users = await query.ToListAsync(cancellationToken).ConfigureAwait(false);

            return(users.Select(u => new UserDto(u)
            {
                Banned = u.IsBanned
            }));
        }
        private static IMongoQueryable <UserModel> ApplyFilters(GetAllUsersQuery filters, IMongoQueryable <UserModel> query)
        {
            if (!string.IsNullOrWhiteSpace(filters.Gender))
            {
                query = query.Where(u => u.Gender == filters.Gender);
            }

            if (!string.IsNullOrWhiteSpace(filters.RoleName))
            {
                query = query.Where(u => u.RoleName == filters.RoleName);
            }

            if (!string.IsNullOrWhiteSpace(filters.Username))
            {
                query = query.Where(u => u.Username == filters.Username);
            }

            return(query);
        }