Example #1
0
        public ActionResult GetFromAndToByCardID(string fromUserID, int cardID, Common.Enums.EnterpriseUserCustomerSource source = Common.Enums.EnterpriseUserCustomerSource.CardList)
        {
            var from = db.Users.FirstOrDefault(s => s.Id == fromUserID);

            if (from == null)
            {
                return(Json(Comm.ToJsonResult("FromUserNoFound", "用户不存在")));
            }
            var api = new Common.TxIm.ImApi();

            var to = (from u in db.Users
                      from c in db.Cards
                      where u.Id == c.UserID && c.ID == cardID
                      select new { u.Id, u.UserName, c.Avatar, NickName = c.Name }).FirstOrDefault();

            if (to == null)
            {
                return(Json(Comm.ToJsonResult("CardNoFound", "卡片不存在")));
            }
            try
            {
                api.ImportUser(from.UserName, from.NickName, from.Avatar);
                api.ImportUser(to.UserName, to.NickName, to.Avatar);
            }
            catch (Exception ex)
            {
                Json(Comm.ToJsonResult("Error", ex.Message));
            }
            //新增客户
            var addcustresult = AddUserCustomer(fromUserID, cardID, source);

            return(Json(Comm.ToJsonResult("Success", "成功", new
            {
                From = new
                {
                    Avatar = from.Avatar.SplitToArray <string>(',')[0],
                    UserID = from.Id,
                    UserName = from.UserName,
                    NickName = from.NickName,
                    Sign = Common.TxIm.SigCheck.Sign(from.UserName),
                },
                To = new
                {
                    Avatar = to.Avatar.SplitToArray <string>(',')[0],
                    UserID = to.Id,
                    UserName = to.UserName,
                    NickName = to.NickName,
                }
            }), JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public ActionResult GetFromAndToUserID(string fromUserName, string toUserName)
        {
            var from = (from u in db.Users
                        from c in db.Cards
                        where u.Id == c.UserID && u.UserName == fromUserName
                        select new { u.Id, u.UserName, c.Avatar, NickName = c.Name }).FirstOrDefault();

            if (from == null)
            {
                return(Json(Comm.ToJsonResult("FromUserNoFound", "发送用户不存在")));
            }
            var api = new Common.TxIm.ImApi();

            var to = db.Users.FirstOrDefault(s => s.UserName == toUserName);

            //if (to == null)
            //{
            //    return Json(Comm.ToJsonResult("CardNoFound", "接收消息用户不存在"));
            //}
            try
            {
                api.ImportUser(from.UserName, from.NickName, from.Avatar);
                api.ImportUser(to.UserName, to.NickName, to.Avatar);
            }
            catch (Exception ex)
            {
                Json(Comm.ToJsonResult("Error", ex.Message));
            }

            return(Json(Comm.ToJsonResult("Success", "成功", new
            {
                From = new
                {
                    Avatar = from.Avatar.SplitToArray <string>(',')[0],
                    UserID = from.Id,
                    UserName = from.UserName,
                    NickName = from.NickName,
                    Sign = Common.TxIm.SigCheck.Sign(from.UserName),
                },
                To = new
                {
                    Avatar = to == null ? "" : to.Avatar,
                    UserID = to == null ? "" : to.Id,
                    UserName = to == null ? "" : to.UserName,
                    NickName = to == null ? "" : to.NickName,
                }
            }), JsonRequestBehavior.AllowGet));
        }