// This is the controller for the Shout view public ActionResult Shout() { ViewBag.Message = "Shout, please!"; if (Request.Form["shouted"] != null) { // send a shout var message = Request.Form["message"].ToString(); var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>(); hub.Clients.All.broadcastMessage("SYSTEM", message); ViewBag.Message = "Message Sent"; var db = ContextFactory.GetContextPerRequest(); Chat newChat = new Core.Chat(); newChat.Time = DateTime.Now; newChat.Name = "SYSTEM"; newChat.Message = message; db.Add(newChat); db.SaveChanges(); } return(View()); }
public void Send(string name, string message) { // Call the broadcastMessage method to update clients. Clients.All.broadcastMessage(name, message); var db = ContextFactory.GetContextPerRequest(); Chat newChat = new Core.Chat(); newChat.Time = DateTime.Now; newChat.Name = name; newChat.Message = message; db.Add(newChat); db.SaveChanges(); }