Exemplo n.º 1
0
        public static int AcceptRequest(LoginUser loginUser, int userID, int chatRequestID, string ipAddress)
        {
            ChatRequest request = ChatRequests.GetChatRequest(loginUser, chatRequestID);

            if (request == null || request.IsAccepted)
            {
                return(-1);
            }
            request.IsAccepted   = true;
            request.TargetUserID = userID;
            request.Collection.Save();

            Chats.JoinChat(loginUser, userID, ChatParticipantType.User, request.ChatID, ipAddress);

            if (request.RequestType == ChatRequestType.External && request.Message.Trim() != "")
            {
                ChatMessage chatMessage = (new ChatMessages(loginUser)).AddNewChatMessage();
                chatMessage.ChatID     = request.ChatID;
                chatMessage.Message    = request.Message.Trim();
                chatMessage.PosterID   = request.RequestorID;
                chatMessage.PosterType = request.RequestorType;
                chatMessage.Collection.Save();
            }

            return(request.ChatID);
        }
        public static ChatRequest GetChatRequest(LoginUser loginUser, int chatRequestID)
        {
            ChatRequests chatRequests = new ChatRequests(loginUser);

            chatRequests.LoadByChatRequestID(chatRequestID);
            if (chatRequests.IsEmpty)
            {
                return(null);
            }
            else
            {
                return(chatRequests[0]);
            }
        }
Exemplo n.º 3
0
        public static bool AreOperatorsAvailable(LoginUser loginUser, int organizationID, int?groupID = null)
        {
            ChatRequests requests = new ChatRequests(loginUser);
            string       sql      = @"SELECT COUNT(*) FROM ChatUserSettings cus WITH(NOLOCK)
                            LEFT JOIN Users u WITH(NOLOCK) ON u.UserID = cus.UserID
                            {0}
                            WHERE cus.IsAvailable = 1
                            AND u.IsChatUser = 1
                            AND u.OrganizationID = @OrganizationID
                            {1}";

            string groupJoinClause  = "";
            string groupWhereClause = "";

            if (groupID != null && groupID != 0)
            {
                groupJoinClause  = @"JOIN GroupUsers ON u.UserID = GroupUsers.UserID";
                groupWhereClause = @"AND GroupUsers.GroupID = @GroupID";
            }

            sql = string.Format(sql, groupJoinClause, groupWhereClause);

            using (SqlCommand command = new SqlCommand())
            {
                command.CommandText = sql;
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@OrganizationID", organizationID);

                if (groupID != null)
                {
                    command.Parameters.AddWithValue("@GroupID", groupID);
                }

                object o     = requests.ExecuteScalar(command);
                int    count = o == DBNull.Value ? 0 : (int)o;
                return(count > 0);
            }
        }
Exemplo n.º 4
0
        public static int GetWaitingRequestCount(LoginUser loginUser, int userID, int organizationID)
        {
            ChatRequests requests = new ChatRequests(loginUser);

            using (SqlCommand command = new SqlCommand())
            {
                command.CommandText = @"
SELECT COUNT(*) FROM ChatRequests cr
LEFT JOIN ChatClients cc ON cc.ChatClientID = cr.RequestorID
WHERE cr.IsAccepted = 0 
AND cr.OrganizationID = @OrganizationID
AND ((DATEADD(second, @Seconds, cc.LastPing) > GETUTCDATE() OR cc.LastPing IS NULL OR cr.RequestorType = 0) AND DATEADD(minute, 30, cr.DateCreated) > GETUTCDATE())
AND (cr.GroupID IS NULL OR cr.GroupID IN (SELECT GroupID FROM GroupUsers WHERE UserID = @UserID))
AND (cr.TargetUserID IS NULL OR cr.TargetUserID = @UserID)
";
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@UserID", userID);
                command.Parameters.AddWithValue("@OrganizationID", organizationID);
                command.Parameters.AddWithValue("@Seconds", StayAliveSeconds);

                object o = requests.ExecuteScalar(command);
                return(o == DBNull.Value ? 0 : (int)o);
            }
        }
 public ChatRequest(DataRow row, ChatRequests chatRequests) : base(row, chatRequests)
 {
     _chatRequests = chatRequests;
 }