示例#1
0
        public void SelCustom(List <WX_Queue> Queue)
        {
            var context = GlobalHost.ConnectionManager.GetHubContext <MobileHub>();
            var Result  = Queue.GroupBy(s => s.OpenID).Select(s => new
            {
                Count = s.Count(),
                info  = s.Select(x => new
                {
                    x.OpenID,
                    x.WX_User.HeadImageUrl,
                    x.WX_User.UserId,
                    x.WX_User.UserNick,
                    x.WX_User.UserName,
                    x.WX_App.AppId,
                    x.MsgType,
                    CreateTime = DateTimeUtility.DATE(Convert.ToDateTime(x.CreateTime)),
                    Content    = XmlUtility.GetSingleNodeInnerText(x.XmlContent, "/xml/Content")
                }).FirstOrDefault()
            });

            foreach (var item in Result)
            {
                context.Clients.User(item.info.UserId.ToString()).PlusUse(Result);
            }
        }
        /// <summary>
        /// 聊天队列
        /// </summary>
        /// <param name="UserId"></param>
        /// <param name="AppId"></param>
        /// <returns></returns>
        public ActionResult SelCustom(int UserId, string AppId)
        {
            //var dic = new Dictionary<string,dynamic>();
            //var userList = new WX_CustomMsgManager().Where(x => x.UserId == UserId && x.AppId == AppId).OrderByDescending(s=>s.CreateTime);
            //foreach (var item in userList)
            //{
            //    if (!dic.ContainsKey(item.OpenID))
            //    {
            //        var msgs = new List<object>();
            //        msgs.Add(new
            //        {
            //            item.OpenID,
            //            item.WX_User.HeadImageUrl,
            //            item.Content,
            //            item.WX_User.UserName,
            //            item.WX_User.UserNick,
            //            CreateTime = DateTimeUtility.DATE(Convert.ToDateTime(item.CreateTime))

            //        });
            //        dic.Add(item.OpenID, new { msgs });
            //    }else
            //    {
            //        var msg = dic[item.OpenID];
            //        msg.msgs.Add(new
            //        {
            //            item.OpenID,
            //            item.WX_User.HeadImageUrl,
            //            item.Content,
            //            item.WX_User.UserName,
            //            item.WX_User.UserNick,
            //            CreateTime = DateTimeUtility.DATE(Convert.ToDateTime(item.CreateTime))
            //        });
            //    }
            //}
            //var result = dic.ToList();
            var userList = new WX_CustomMsgManager().Where(x => x.UserId == UserId && x.AppId == AppId).OrderByDescending(s => s.CreateTime);
            var result   = userList.GroupBy(s => s.OpenID).Select(x => new
            {
                Count = 0,
                info  = x.Select(s => new {
                    s.OpenID,
                    s.WX_User.HeadImageUrl,
                    s.Content,
                    s.WX_User.UserName,
                    s.WX_User.UserNick,
                    CreateTime = DateTimeUtility.DATE(Convert.ToDateTime(s.CreateTime))
                }).FirstOrDefault()
            });

            return(Json(result, JsonRequestBehavior.AllowGet));
        }