Example #1
0
        public ActionResult PostMessage(int receiver_id, string content)
        {
            var message = new Entity.Message
            {
                Content    = content,
                Read       = false,
                ReceiverID = receiver_id,
                Time       = DateTime.Now,
                SenderID   = ViewBag.CurrentUser.ID
            };

            DbContext.Messages.Add(message);
            DbContext.SaveChanges();
            var name1 = DbContext.Users.Find(message.ReceiverID).Username;
            var name2 = DbContext.Users.Find(message.SenderID).Username;

            SignalR.CodeCombHub.context.Clients.Group(name1).onMessageReceived(message.ID);
            SignalR.CodeCombHub.context.Clients.Group(name2).onMessageReceived(message.ID);
            SignalR.MobileHub.context.Clients.Group(name1).onMessageReceived(new CodeComb.Models.WebAPI.Message
            {
                Content    = message.Content,
                Time       = message.Time,
                SenderID   = message.SenderID,
                ReceiverID = message.ReceiverID
            });
            SignalR.MobileHub.context.Clients.Group(name2).onMessageReceived(new CodeComb.Models.WebAPI.Message
            {
                Content    = message.Content,
                Time       = message.Time,
                SenderID   = message.SenderID,
                ReceiverID = message.ReceiverID
            });
            SignalR.MobileHub.PushTo(message.ReceiverID, message.Sender.Nickname + ":" + message.Content);
            return(Content("OK"));
        }
Example #2
0
 public ChatRecord(Entity.Message message)
 {
     ID               = message.ID;
     Time             = message.Time.ToString("yyyy-MM-dd HH:mm:ss");
     Content          = HttpUtility.HtmlEncode(message.Content);
     SenderID         = message.SenderID;
     ReceiverID       = message.ReceiverID;
     SenderNickname   = Helpers.ColorName.GetNicknameHtml(message.Sender.Nickname, message.Sender.Ratings.Sum(x => x.Credit) + 1500);
     ReceiverNickname = Helpers.ColorName.GetNicknameHtml(message.Receiver.Nickname, message.Receiver.Ratings.Sum(x => x.Credit) + 1500);
     Gravatar         = Gravatar = "<img class='post-face' src='" + Helpers.Gravatar.GetAvatarURL(message.Sender.Gravatar, 180) + "' />";
 }
Example #3
0
        public ActionResult SendMessage(string Token, int UserID, string Content)
        {
            var user = CheckUser(Token);

            if (user == null)
            {
                return(Json(new Base
                {
                    Code = 500,
                    IsSuccess = false,
                    Info = "AccessToken不正确"
                }));
            }
            var msg = new Entity.Message
            {
                Content    = Content,
                SenderID   = user.ID,
                ReceiverID = UserID,
                Time       = DateTime.Now,
                Read       = false
            };

            DbContext.Messages.Add(msg);
            DbContext.SaveChanges();
            var name1 = DbContext.Users.Find(msg.ReceiverID).Username;
            var name2 = DbContext.Users.Find(msg.SenderID).Username;

            SignalR.CodeCombHub.context.Clients.Group(name1).onMessageReceived(msg.ID);
            SignalR.CodeCombHub.context.Clients.Group(name2).onMessageReceived(msg.ID);
            SignalR.MobileHub.context.Clients.Group(name1).onMessageReceived(new CodeComb.Models.WebAPI.Message
            {
                Content    = msg.Content,
                Time       = msg.Time,
                SenderID   = msg.SenderID,
                ReceiverID = msg.ReceiverID
            });
            SignalR.MobileHub.context.Clients.Group(name2).onMessageReceived(new CodeComb.Models.WebAPI.Message
            {
                Content    = msg.Content,
                Time       = msg.Time,
                SenderID   = msg.SenderID,
                ReceiverID = msg.ReceiverID
            });
            SignalR.MobileHub.PushTo(msg.ReceiverID, msg.Sender.Nickname + ":" + msg.Content);
            return(Json(new Base
            {
                Code = 0,
                IsSuccess = true,
                Info = ""
            }));
        }
Example #4
0
 /// <summary>
 /// 发送消息
 /// </summary>
 /// <param name="m"></param>
 public static bool AddMsg(Entity.Message m)
 {
     System.Data.DataTable dt = DAL.MessageTo.SearchPID();
     try
     {
         for (int i = 0; i < dt.Rows.Count; i++)
         {
             m.pID = int.Parse(dt.Rows[i][0].ToString());
             DAL.MessageTo.AddMsg(m);
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #5
0
 private void btn_send_Click(object sender, EventArgs e)
 {
     if (this.txt_text.Text == "")
     {
         Msg.Box.Show("请输入您要发送的消息!");
         return;
     }
     Entity.Message m = new Entity.Message();
     m.uID   = user.uID;
     m.mText = this.txt_text.Text;
     m.mTIme = System.DateTime.Now;
     if (BLL.MessageTo.AddMsg(m) == true)
     {
         Msg.Box.Show("恭喜您,消息发送成功!");
         this.dgv_history.DataSource = BLL.MessageTo.LoadMsg();
         this.txt_text.Clear();
     }
 }
Example #6
0
 public static Entity.Message ConvertToEntity(Model.Message message)
 {
     Entity.Message entityMessage = new Entity.Message();
     try
     {
         entityMessage.senderId     = message.SenderId;
         entityMessage.sendDateTime = message.SendDateTime;
         entityMessage.seen         = message.Seen;
         entityMessage.receiverId   = message.ReceiverId;
         entityMessage.messageId    = message.MessageId;
         entityMessage.message1     = message.Messages;
         entityMessage.sendReceive  = message.SendReceive;
         return(entityMessage);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Example #7
0
 /// <summary>
 /// 创建 <see cref="FileReceivedEventArgs" /> 的新实例
 /// </summary>
 public FileReceivedEventArgs(Entity.Host host, Entity.Message message, Entity.FileTaskInfo file)
 {
     Host    = host;
     Message = message;
     File    = file;
 }
 public void Update(Entity.Message Message)
 {
     _context.Entry(Message).State = EntityState.Modified;
 }
 public void Insert(Entity.Message Message)
 {
     _context.Entry(Message).State = EntityState.Added;
 }
Example #10
0
 /// <summary>
 /// 更新状态
 /// </summary>
 /// <returns></returns>
 public static void UpState(Entity.Message msg)
 {
     EDAL.MsgDAL.UpState(msg);
 }
Example #11
0
 /// <summary>
 /// 查询发信人
 /// </summary>
 /// <param name="msg"></param>
 /// <returns></returns>
 public static int SendID(Entity.Message msg)
 {
     return(EDAL.MsgDAL.SendID(msg));
 }
Example #12
0
 /// <summary>
 /// 加载已读消息
 /// </summary>
 /// <returns></returns>
 public static DataTable LoadMsgYse(Entity.Message m)
 {
     return(EDAL.MsgDAL.LoadMsgYse(m));
 }
Example #13
0
        /// <summary>
        /// 更新状态
        /// </summary>
        /// <returns></returns>
        public static int UpState(Entity.Message msg)
        {
            string sql = "update Message set MState='已读' where MID=" + msg.mID + "";

            return((int)DBHelper.GetLine(sql));
        }
Example #14
0
        /// <summary>
        /// 查询发信人
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static int SendID(Entity.Message msg)
        {
            string sql = "select MSend from Message where MID=" + msg.mID + "";

            return((int)DBHelper.GetScalar(sql));
        }
Example #15
0
        /// <summary>
        /// 加载已读消息
        /// </summary>
        /// <returns></returns>
        public static DataTable LoadMsgYse(Entity.Message m)
        {
            string sql = "select MID,MText,MTime from Message where MState='已读' and PID=" + m.pID + "";

            return(DBHelper.GetDT(sql));
        }
Example #16
0
 public ActionResult SendMessage(string Token, int UserID, string Content)
 {
     var user = CheckUser(Token);
     if (user == null)
         return Json(new Base
         {
             Code = 500,
             IsSuccess = false,
             Info = "AccessToken不正确"
         });
     var msg = new Entity.Message
     {
         Content = Content,
         SenderID = user.ID,
         ReceiverID = UserID,
         Time = DateTime.Now,
         Read = false
     };
     DbContext.Messages.Add(msg);
     DbContext.SaveChanges();
     var name1 = DbContext.Users.Find(msg.ReceiverID).Username;
     var name2 = DbContext.Users.Find(msg.SenderID).Username;
     SignalR.CodeCombHub.context.Clients.Group(name1).onMessageReceived(msg.ID);
     SignalR.CodeCombHub.context.Clients.Group(name2).onMessageReceived(msg.ID);
     SignalR.MobileHub.context.Clients.Group(name1).onMessageReceived(new CodeComb.Models.WebAPI.Message
     {
         Content = msg.Content,
         Time = msg.Time,
         SenderID = msg.SenderID,
         ReceiverID = msg.ReceiverID
     });
     SignalR.MobileHub.context.Clients.Group(name2).onMessageReceived(new CodeComb.Models.WebAPI.Message
     {
         Content = msg.Content,
         Time = msg.Time,
         SenderID = msg.SenderID,
         ReceiverID = msg.ReceiverID
     });
     SignalR.MobileHub.PushTo(msg.ReceiverID, msg.Sender.Nickname + ":" + msg.Content);
     return Json(new Base
     {
         Code = 0,
         IsSuccess = true,
         Info = ""
     });
 }