public List <PrivateChatMessage> GetScrollingChatData(string fromid, string toid, int start = 10, int length = 1) { takeCounter = (length * start); // 20 skipCounter = ((length - 1) * start); // 10 using (MeHelpChat dc = new MeHelpChat()) { List <PrivateChatMessage> msg = new List <PrivateChatMessage>(); var v = (from a in dc.ChatPrivMensMaster join b in dc.ChatPrivMensDetal 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); } }
public List <PrivateChatMessage> GetPrivateMessage(string fromid, string toid, int take) { using (MeHelpChat dc = new MeHelpChat()) { List <PrivateChatMessage> msg = new List <PrivateChatMessage>(); var v = (from a in dc.ChatPrivMensMaster join b in dc.ChatPrivMensDetal 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); } }