Beispiel #1
0
        public IEnumerable <PrivateChatMessage> GetScrollingChatData(string fromid, string toid, int start = 10, int length = 1)
        {
            takeCounter = (length * start);       // 20
            skipCounter = ((length - 1) * start); // 10

            using (SignalREntities dc = new SignalREntities())
            {
                var msg = new List <PrivateChatMessage>();
                var v   = (from a in dc.tblChatPrivateMessageMasters
                           join b in dc.tblChatPrivateMessageDetails on a.EmailID equals b.MasterEmailID into cc
                           from c in cc
                           where (c.MasterEmailID.Equals(fromid) && c.ChatToEmailID.Equals(toid)) || (c.MasterEmailID.Equals(toid) && c.ChatToEmailID.Equals(fromid))
                           orderby c.ID descending
                           select new
                {
                    UserName = a.UserName,
                    Message = c.Message,
                    ID = c.ID
                }).Take(takeCounter).Skip(skipCounter).ToList();

                foreach (var a in v)
                {
                    var res = new PrivateChatMessage()
                    {
                        UserName = a.UserName,
                        Message  = a.Message
                    };
                    msg.Add(res);
                }
                return(msg);
            }
        }
Beispiel #2
0
        public IEnumerable <PrivateChatMessage> GetPrivateMessage(string fromid, string toid, int take)
        {
            using (SignalREntities dc = new SignalREntities())
            {
                var msg = new List <PrivateChatMessage>();

                var v = (from a in dc.tblChatPrivateMessageMasters
                         join b in dc.tblChatPrivateMessageDetails on a.EmailID equals b.MasterEmailID into cc
                         from c in cc
                         where (c.MasterEmailID.Equals(fromid) && c.ChatToEmailID.Equals(toid)) || (c.MasterEmailID.Equals(toid) && c.ChatToEmailID.Equals(fromid))
                         orderby c.ID descending
                         select new
                {
                    UserName = a.UserName,
                    Message = c.Message,
                    ID = c.ID
                }).Take(take).ToList();
                v = v.OrderBy(s => s.ID).ToList();

                foreach (var a in v)
                {
                    var res = new PrivateChatMessage()
                    {
                        UserName = a.UserName,
                        Message  = a.Message
                    };
                    msg.Add(res);
                }
                return(msg);
            }
        }