コード例 #1
0
        public ActionResult ChatPost(Chat_Data_Pass model)
        {
            if (model != null)
            {
                var result = _chat.Save_Message(model);

                return(Content(result.ToString()));
            }
            return(Content(Boolean.FalseString));
        }
コード例 #2
0
ファイル: ChatManager.cs プロジェクト: RezaHoque/compro
        public bool Save_Message(Chat_Data_Pass model)
        {
            try
            {
                string senderID   = Current_User_id;
                string RecieverID = model.PartnerId;
                string MessageThreadID;

                if (_data.SendMessage.Any(x => (x.MessageThreadID.Contains(senderID)) && (x.MessageThreadID.Contains(RecieverID))))
                {
                    var allMessage = _data.SendMessage.FirstOrDefault(x => (x.MessageThreadID.Contains(senderID)) && (x.MessageThreadID.Contains(RecieverID)));
                    MessageThreadID = allMessage.MessageThreadID;
                }

                else
                {
                    MessageThreadID = senderID + ',' + RecieverID;
                }



                MessageSendingModel sendmessage   = new MessageSendingModel();
                MessageRecieveModel recivemessage = new MessageRecieveModel();


                sendmessage.SenderID        = senderID;
                sendmessage.Massage         = model.Message;
                sendmessage.MessageThreadID = MessageThreadID;
                sendmessage.Date_Time       = DateTime.Now;
                _data.SendMessage.Add(sendmessage);

                recivemessage.RecieverID      = RecieverID;
                recivemessage.MessageThreadID = MessageThreadID;
                _data.RecieveMessage.Add(recivemessage);
                _data.SaveChanges();

                return(true);
            }
            catch
            {
                return(false);
            }
        }