示例#1
0
        public void SendMsg(string fromId, string toId, string strMsg)
        {
            //chatmsg.Add(new ChatMsgModel { fromId = fromId, toId = toId, strMsg = strMsg, createDte = DateTime.Now });

            using (ApplicantDBEntities db = new ApplicantDBEntities())
            {
                core_chat chatinfo = new core_chat
                {
                    chatId      = 0,
                    msgfrom     = fromId,
                    msgto       = toId,
                    msg         = strMsg,
                    createdby   = fromId,
                    createddate = DateTime.Now,
                    isread      = 0
                };

                db.core_chat.Add(chatinfo);
                db.SaveChanges();
            }

            foreach (var row in UsersList.Where(wr => wr.userId == toId))
            {
                Clients.Client(row.connectionId).getChatMsg(fromId, toId, strMsg, DateTime.Now);
            }
        }
示例#2
0
        public void Viewmsg(string fromId, string toId, string toName)
        {
            List <ChatMsgModel> chatmsg = new List <ChatMsgModel>();

            using (ApplicantDBEntities db = new ApplicantDBEntities())
            {
                var qchatFromMe = db.core_chat.Where(wr => wr.msgfrom == fromId && wr.msgto == toId).OrderByDescending(aa => aa.createddate).Take(10).ToList();
                var qchatToMe   = db.core_chat.Where(wr => wr.msgfrom == toId && wr.msgto == fromId).OrderByDescending(aa => aa.createddate).Take(10).ToList();


                foreach (var row in qchatFromMe.OrderBy(aa => aa.createddate))
                {
                    chatmsg.Add(new ChatMsgModel {
                        fromId = row.msgfrom, toId = row.msgto, strMsg = row.msg, iconClass = "bubble bubble--alt", createDte = row.createddate
                    });
                }

                foreach (var row in qchatToMe.OrderBy(aa => aa.createddate))
                {
                    chatmsg.Add(new ChatMsgModel {
                        fromId = row.msgfrom, toId = row.msgto, strMsg = "<img src='http://apps.fastgroup.biz/201pic/48px/" + toId + ".jpg' width='32' height='32' />&nbsp;<strong>" + toName + "</strong><br/>" + row.msg, iconClass = "bubble", createDte = row.createddate
                    });
                }

                var msglist = chatmsg.OrderBy(aa => aa.createDte).ToList();

                //begin:update msg status to read
                var qMsg = db.core_chat.Where(wr => wr.msgfrom == toId && wr.msgto == fromId && wr.isread == 0);
                foreach (var row in qMsg)
                {
                    row.isread = 1;
                }
                db.SaveChanges();
                //end:

                //begin: broard cast info
                var frindOnlineExceptMe = UsersList.Except(UsersList.Where(wr => wr.userId == fromId).ToList()).Select(aa => new { aa.userId, aa.userName, msgCount = countUnreadMsg(aa.userId, fromId) }).Distinct().ToList();
                Clients.Caller.getOnline(frindOnlineExceptMe);
                Clients.Caller.getfriendmsg(msglist);
                //end:
            }
        }