Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "MessageId,MsgTxt,DatePosted")] Message message)
        {
            if (ModelState.IsValid)
            {
                db.Messages.Add(message);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(message));
        }
Ejemplo n.º 2
0
        public ActionResult Create(MsgModels msgmodels)
        {
            if (ModelState.IsValid)
            {
                msgmodels.Date = DateTime.Today.Date;
                db.MsgModels.Add(msgmodels);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(msgmodels));
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //send message to hub
            Console.WriteLine("enter \"q\" to quit application");
            string body;

            do
            {
                Console.WriteLine("Enter message:");

                body = Console.ReadLine();

                if (body.ToLower() == "q")
                {
                    Environment.Exit(0);
                }

                Message message = new Message(body, DateTime.Now, false);

                var connection = new HubConnection("http://localhost:20135");

                var proxy = connection.CreateHubProxy("chatHub");

                try {
                    connection.Start().Wait();

                    if (connection.State == ConnectionState.Connected)
                    {
                        proxy.Invoke("receiveNotification", message);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Cannot connect to client. Please make sure the MVC application is started at port 20135");
                }

                //insert message in database
                using (var db = new MsgContext())
                {
                    db.Messages.Add(new Message(body, DateTime.Now, false));
                    db.SaveChanges();
                    Console.WriteLine("Message saved to DB");
                }
            }while (!String.IsNullOrWhiteSpace(body) || body.ToLower() != "q");
        }