Пример #1
0
        public List<MessageInfo> GetMessageHistoryForSpecifiedChatBetweenDates(string chatname, DateTime first, DateTime second)
        {
            if (first > second)
            {
                DateTime tmpdt = first;
                first = second;
                second = tmpdt;
            }

            List<MessageInfo> messageshistory = new List<MessageInfo>();

            var history = from h in this._context.History
                          join c in this._context.Chat on h.IdChat_Chat equals c.IdChat
                          join u in this._context.ChatUser on h.IdUser_ChatUser equals u.IdUser
                          where c.ChatTitle == chatname && h.MessageDate >= first && h.MessageDate <= second
                          select new
                          {
                              Username = u.UserName,
                              Message = h.Message,
                              MsgDate = h.MessageDate,
                              MsgId = h.IdHistory,
                              ChatName = c.ChatTitle
                          };

            foreach (var msg in history)
            {
                MessageInfo mi = new MessageInfo();
                mi.userName = msg.Username;
                mi.message = msg.Message;
                mi.messageDate = msg.MsgDate;
                mi.messageId = msg.MsgId;
                mi.chatTitle = msg.ChatName;

                messageshistory.Add(mi);
            }

            return messageshistory;
        }
Пример #2
0
        public List<MessageInfo> GetNewMessages(int lastMsgId, string chatName)
        {
            List<MessageInfo> newMessages = new List<MessageInfo>();

            var newmsgs = from h in this._context.History
                          join c in this._context.Chat on h.IdChat_Chat equals c.IdChat
                          join u in this._context.ChatUser on h.IdUser_ChatUser equals u.IdUser
                          where h.IdHistory > lastMsgId && c.ChatTitle == chatName
                          select new
                          {
                              Username = u.UserName,
                              Message = h.Message,
                              MsgDate = h.MessageDate,
                              MsgId = h.IdHistory,
                              ChatName = c.ChatTitle
                          };

            foreach (var msg in newmsgs)
            {
                MessageInfo nm = new MessageInfo();
                nm.userName = msg.Username;
                nm.message = msg.Message;
                nm.messageDate = msg.MsgDate;
                nm.messageId = msg.MsgId;
                nm.chatTitle = msg.ChatName;

                newMessages.Add(nm);
            }

            return newMessages;
        }
Пример #3
0
        public List<MessageInfo> GetMessageHistoryForSpecifiedChatAndUser(string chatname, string username)
        {
            List<MessageInfo> messageshistory = new List<MessageInfo>();

            var history = from h in this._context.History
                          join c in this._context.Chat on h.IdChat_Chat equals c.IdChat
                          join u in this._context.ChatUser on h.IdUser_ChatUser equals u.IdUser
                          where c.ChatTitle == chatname && u.UserName == username
                          select new
                          {
                              Username = u.UserName,
                              Message = h.Message,
                              MsgDate = h.MessageDate,
                              MsgId = h.IdHistory,
                              ChatName = c.ChatTitle
                          };

            foreach (var msg in history)
            {
                MessageInfo mi = new MessageInfo();
                mi.userName = msg.Username;
                mi.message = msg.Message;
                mi.messageDate = msg.MsgDate;
                mi.messageId = msg.MsgId;
                mi.chatTitle = msg.ChatName;

                messageshistory.Add(mi);
            }

            return messageshistory;
        }