Esempio n. 1
0
 public bool SaveChatMessage(ChatMessage msg)
 {
     try
     {
         using (var context = new EntityContext())
         {
             context.ChatMessage.Add(msg);
             context.SaveChanges();
             return true;
         }
     }
     catch (Exception ex)
     {
         return false;
     }
 }
Esempio n. 2
0
        public ActionResult SendMessage(string message, string username)
        {
            var chatMessage = new ChatMessage()
            {
                ChatMsgId = Guid.NewGuid(),
                ChatMsgText = message,
                Author = username,
                TimeStamp = DateTime.Now
            };

            chatService.SaveChatMessage(chatMessage);

            var pusher = new Pusher(
                    WebConfigurationManager.AppSettings["PusherAppId"],
                    WebConfigurationManager.AppSettings["PusherAppKey"],
                    WebConfigurationManager.AppSettings["PusherAppSecret"]);
            var result = pusher.Trigger("chat_channel", "chat_event", new { message, username, chatMsgId = chatMessage.ChatMsgId });

            return new EmptyResult();
        }