예제 #1
0
        public async Task <SearchResult> Get(string keywords)
        {
            string currentUserId = identity.CurrentUserId;
            var    users         = await usersRepo.Search(keywords, currentUserId);

            var messages = await messagesRepo.Search(keywords, currentUserId);

            var chatRooms = await chatRoomsRepo.Search(keywords, currentUserId);

            var result = new SearchResult
            {
                Users     = users.Select(x => mapper.Map <UserEntity, UserViewModel>(x)).ToArray(),
                Messages  = messages.Select(x => mapper.Map <MessageEntity, MessageViewModel>(x)).ToArray(),
                ChatRooms = chatRooms.Select(x => mapper.Map <ChatRoomEntity, ChatRoomViewModel>(x)).Select(x =>
                {
                    x.RoomName     = x.GetRoomName(currentUserId);
                    x.Participants = String.IsNullOrWhiteSpace(keywords) ? x.Participants : x.Participants.Where(u => u.UserName.Contains(keywords) || u.Email.Contains(keywords)).ToList();
                    return(x);
                }).ToArray()
            };

            return(result);
        }