Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "MessageID,Date,SenderID,ReceiverID,Text")] Message message)
        {
            if (ModelState.IsValid)
            {
                ViewBag.badWord = HomeController.consistBadWord(message.Text);
                if (ViewBag.badWord != "")
                {
                    return(View("BadWord"));
                }

                db.Messages.Add(message);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ReceiverID = new SelectList(db.Users, "UserID", "Nick", message.ReceiverID);
            ViewBag.SenderID   = new SelectList(db.Users, "UserID", "Nick", message.SenderID);
            return(View(message));
        }
Ejemplo n.º 2
0
        public ActionResult SpecialCreate([Bind(Include = "MessageID,Date,SenderID,ReceiverID,Text")] Message message)
        {
            if (ModelState.IsValid)
            {
                ViewBag.badWord = HomeController.consistBadWord(message.Text);
                if (ViewBag.badWord != "")
                {
                    return(View("BadWord"));
                }

                message.Date = DateTime.Now;

                int s = Int32.Parse(Session["UserID"].ToString());
                int r = Int32.Parse(Session["ReceiverID"].ToString());

                message.SenderID   = s;
                message.ReceiverID = r;
                db.Messages.Add(message);
                db.SaveChanges();

                if (Session["t"] != null)
                {
                    int t = Int32.Parse(Session["t"].ToString());
                    Session["t"] = null;
                    return(RedirectToAction("Thread", "Home", new { id = t }));
                }
                else
                {
                    return(RedirectToAction("Mymessages", "Home", new { id = message.SenderID }));
                }
            }

            ViewBag.ReceiverID = new SelectList(db.Users, "UserID", "Nick", message.ReceiverID);
            ViewBag.SenderID   = new SelectList(db.Users, "UserID", "Nick", message.SenderID);
            return(View(message));
        }