Esempio n. 1
0
        public void SearchUsersForAddUsersToChat(string userName, string userGuid, string chatGuid)
        {
            var userElasticResult = _userRepository.Get(userGuid);

            if (!userElasticResult.Success)
            {
                Clients.Caller.onSearchUsersForAddUsersToChatCaller(
                    JsonConvert.SerializeObject(new { error = true, message = UserErrorMessage }));
                return;
            }

            var chatElasticResult = _chatRepository.Get(chatGuid);

            if (!chatElasticResult.Success)
            {
                Clients.Caller.onSearchUsersForAddUsersToChatCaller(
                    JsonConvert.SerializeObject(new { error = true, message = ChatErrorMessage }));
                return;
            }

            var searchElasticResult = _userRepository.SearchByUserName(userName);

            if (!searchElasticResult.Success)
            {
                Clients.Caller.onSearchUsersForAddUsersToChatCaller(
                    JsonConvert.SerializeObject(new { error = true, message = ServerErrorMessage }));
                return;
            }

            var users = searchElasticResult.Value;

            var chatUserElasticResult = _chatUserRepository.GetAllByChatGuid(chatGuid);

            if (!chatUserElasticResult.Success)
            {
                Clients.Caller.onSearchUsersForAddUsersToChatCaller(
                    JsonConvert.SerializeObject(new { error = true, message = ServerErrorMessage }));
                return;
            }

            var chatUsers = chatUserElasticResult.Value;

            var searchedUsers = users.Where(u => chatUsers.All(cu => cu.UserGuid != u.Guid))
                                .Select(u => new { u.Guid, u.UserName })
                                .ToArray();

            Clients.Caller.onSearchUsersForAddUsersToChatCaller(JsonConvert.SerializeObject(searchedUsers));
        }
Esempio n. 2
0
        public string GetAllChatUsersForChat(string chatGuid)
        {
            var chatUserlasticResult = _chatUserRepository.GetAllByChatGuid(chatGuid);

            if (!chatUserlasticResult.Success)
            {
                return(JsonConvert.SerializeObject(new List <ElasticChat>()));
            }

            var userElasticResult =
                _userRepository.GetAllByGuids(chatUserlasticResult.Value.Select(c => c.UserGuid).ToArray());

            if (!userElasticResult.Success)
            {
                return(JsonConvert.SerializeObject(new List <ElasticChat>()));
            }

            return(JsonConvert.SerializeObject(userElasticResult.Value));
        }