Ejemplo n.º 1
0
        private ChatVM GetChatVM(int connectionId = -1)
        {
            var    userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            ChatVM chatVM = new ChatVM();

            chatVM.Connections = dataBaseRepository.GetAllConnections(userId);
            ConnectionVM tmpCvm = new ConnectionVM();

            //Find selected connection
            foreach (ConnectionVM cvm in chatVM.Connections)
            {
                if (cvm.Id == connectionId)
                {
                    connectionId = cvm.Id;
                    tmpCvm       = cvm;
                }
            }

            //If not found assign first connection
            if (connectionId == -1 && chatVM.Connections.Count > 0)
            {
                connectionId = chatVM.Connections[0].Id;
                tmpCvm       = chatVM.Connections[0];
            }

            //Get friend id
            foreach (UserDetails ud in tmpCvm.UserList)
            {
                if (ud.Id != userId)
                {
                    chatVM.CurrentFriendId = ud.Id;
                }
            }
            chatVM.SelectedConnection = connectionId;
            chatVM.Messages           = dataBaseRepository.GetMessages(connectionId);
            chatVM.CurrentUserId      = userId;

            return(chatVM);
        }