public ChatMessageConnection getChatMessageConnection(Chat chat, Message m)
 {
     var cConnection = (from c in db.ChatMessageConnections
                        where c.ChatID == chat.ID && c.MessageID == m.ID
                        select c).SingleOrDefault();
     return cConnection;
 }
 public bool AddMessageToChat(Chat c, Message toAdd)
 {
     ChatMessageConnection cm = new ChatMessageConnection();
     cm.ChatID = c.ID;
     cm.MessageID = toAdd.ID;
     db.ChatMessageConnections.Add(cm);
     return db.SaveChanges() != 0;
 }
        public ActionResult PostMessage(FormCollection collection, int chatID)
        {
            Message m = new Message();
            m.UserID = collection["userid"];
            m.UserName = collection["username"];
            m.Text = collection["messageText"];
            ApplicationUser a = accountService.getUserByID(m.UserID);
            m.UserProfilePic = a.ProfilePic;
            m.DateInserted = DateTime.Now;

            Chat c = chatService.getChatByID(chatID);

            chatService.AddMessage(m);
            chatService.AddMessageToChat(c, m);

            var currMessages = chatService.GetMessagesByChat(c);

            return Json(currMessages, JsonRequestBehavior.AllowGet);
        }
        public bool AddMessage(Message m)
        {
            db.Messages.Add(m);

            return db.SaveChanges() != 0;
        }
 public bool RemoveMessage(Message m)
 {
     db.Messages.Remove(m);
     return db.SaveChanges() != 0;
 }