/// <summary>
 /// Deprecated Method for adding a new object to the ChatSessions EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToChatSessions(ChatSession chatSession)
 {
     base.AddObject("ChatSessions", chatSession);
 }
 /// <summary>
 /// Create a new ChatSession object.
 /// </summary>
 /// <param name="chatSessionId">Initial value of the ChatSessionId property.</param>
 /// <param name="fromUserId">Initial value of the FromUserId property.</param>
 /// <param name="toUserId">Initial value of the ToUserId property.</param>
 /// <param name="chatState">Initial value of the ChatState property.</param>
 public static ChatSession CreateChatSession(global::System.Int32 chatSessionId, global::System.Int32 fromUserId, global::System.Int32 toUserId, global::System.String chatState)
 {
     ChatSession chatSession = new ChatSession();
     chatSession.ChatSessionId = chatSessionId;
     chatSession.FromUserId = fromUserId;
     chatSession.ToUserId = toUserId;
     chatSession.ChatState = chatState;
     return chatSession;
 }
        public StatusResponse InviteUser(string sessionID, 
			string recipientMSISDN, string challenge)
        {
            ExecuteAndHandleExceptions(() =>
            {
                User senderUser = CheckUserSession(sessionID);

                CheckMSISDN(recipientMSISDN);
                User recipientUser = CheckIfUserIsOnline(recipientMSISDN);
                CheckChallengeCode(challenge);

                if (senderUser.UserId == recipientUser.UserId)
                {
                    throw new ErrorResponseException(HttpStatusCode.NotFound,
                        "ERR_AUTO_CHAT", "Users cannot send chat invitations to themselves.");
                }

                DeleteChatSession(senderUser, recipientUser);

                CryptoChatEntities context = new CryptoChatEntities();

                // Create a new chat session between the users
                ChatSession newChatSession = new ChatSession();
                newChatSession.FromUserId = senderUser.UserId;
                newChatSession.ToUserId = recipientUser.UserId;
                newChatSession.ChatState = ChatSessionState.CHALLENGE_SENT.ToString();
                context.ChatSessions.AddObject(newChatSession);
                context.SaveChanges();

                // Send the challenge to the recipient user (through a message)
                SendMessage(senderUser, recipientUser, MessageType.MSG_CHALLENGE, challenge);
            });
            return new StatusResponse();
        }