public static ChatParticipant GetChatParticipant(LoginUser loginUser, int id, ChatParticipantType type, int chatID) { ChatParticipants chatParticipants = new ChatParticipants(loginUser); using (SqlCommand command = new SqlCommand()) { //SELECT * FROM ChatParticipants WHERE ChatID = @ChatID AND ParticipantType = @ParticipantType AND ParticipantID = @ParticipantID if (type == ChatParticipantType.External) { command.CommandText = @" SELECT cp.*, cc.FirstName, cc.LastName, cc.Email, cc.CompanyName, CASE WHEN DATEDIFF(second, cc.LastPing, GETUTCDATE()) < 15 THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT) END AS IsOnline FROM ChatParticipants cp LEFT JOIN ChatClients cc ON cc.ChatClientID = cp.ParticipantID WHERE cp.ChatID = @ChatID AND cp.ParticipantType = 1 AND cp.ParticipantID = @ParticipantID "; } else { command.CommandText = @" SELECT cp.*, u.FirstName, u.LastName, u.Email, o.Name, CASE WHEN DATEDIFF(second, u.LastPing, GETUTCDATE()) < 15 THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT) END AS IsOnline FROM ChatParticipants cp LEFT JOIN Users u ON u.UserID = cp.ParticipantID LEFT JOIN Organizations o ON o.OrganizationID = u.OrganizationID WHERE cp.ChatID = @ChatID AND cp.ParticipantType = 0 AND cp.ParticipantID = @ParticipantID "; } command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@ChatID", chatID); command.Parameters.AddWithValue("@ParticipantID", id); chatParticipants.Fill(command); } if (chatParticipants.IsEmpty) { return(null); } return(chatParticipants[0]); }