/// <summary>
 /// Create a new Message object.
 /// </summary>
 /// <param name="messageId">Initial value of the MessageId property.</param>
 /// <param name="fromUserId">Initial value of the FromUserId property.</param>
 /// <param name="toUserId">Initial value of the ToUserId property.</param>
 /// <param name="msgType">Initial value of the MsgType property.</param>
 /// <param name="msgDate">Initial value of the MsgDate property.</param>
 /// <param name="msgText">Initial value of the MsgText property.</param>
 public static Message CreateMessage(global::System.Int32 messageId, global::System.Int32 fromUserId, global::System.Int32 toUserId, global::System.String msgType, global::System.DateTime msgDate, global::System.String msgText)
 {
     Message message = new Message();
     message.MessageId = messageId;
     message.FromUserId = fromUserId;
     message.ToUserId = toUserId;
     message.MsgType = msgType;
     message.MsgDate = msgDate;
     message.MsgText = msgText;
     return message;
 }
        private void SendMessage(User senderUser, User recipientUser, 
			MessageType messageType, string msgText)
        {
            Message msg = new Message();
            msg.FromUserId = senderUser.UserId;
            msg.ToUserId = recipientUser.UserId;
            msg.MsgType = messageType.ToString();
            msg.MsgDate = DateTime.Now;
            msg.MsgText = msgText;
            CryptoChatEntities context = new CryptoChatEntities();
            context.Messages.AddObject(msg);
            context.SaveChanges();
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Messages EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToMessages(Message message)
 {
     base.AddObject("Messages", message);
 }
        internal static void SendMessageToAllOnlineUsers(
			User senderUser, MessageType msgType, string msgText)
        {
            DateTime minAllowedLastActivityTime =
                DateTime.Now.AddSeconds(-Settings.Default.HttpSessionTimeoutSeconds);
            CryptoChatEntities context = new CryptoChatEntities();
            var allUserIds =
                from u in context.Users
                where u.LastActivity >= minAllowedLastActivityTime
                select u.UserId;
            foreach (var recipientUserId in allUserIds)
            {
                if (senderUser.UserId != recipientUserId)
                {
                    Message msg = new Message();
                    msg.FromUserId = senderUser.UserId;
                    msg.ToUserId = recipientUserId;
                    msg.MsgType = msgType.ToString();
                    msg.MsgText = msgText;
                    msg.MsgDate = DateTime.Now;
                    context.Messages.AddObject(msg);
                }
            }
            context.SaveChanges();
        }