public IActionResult Newacomment(string text, int mid, int uid, int pid)
        {
            User cur_user = HttpContext.Session.GetObjectFromJson <User>("cur_user");

            if (cur_user.UserId != uid)
            {
                Console.WriteLine("HACKER HAS BEEN DETECTED!");
                return(RedirectToAction("Showuser", new{ id = pid }));
            }

            Acomment newC = new Acomment()
            {
                Text       = text,
                AmessageId = mid,
                UserId     = uid,
            };

            _context.Add(newC);
            _context.SaveChanges();
            if (ModelState.IsValid)
            {
                HttpContext.Session.SetObjectAsJson("acerrors", null);
                return(RedirectToAction("Activity", new{ id = pid }));
            }
            else
            {
                string messages = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage));
                Console.WriteLine(messages);
                HttpContext.Session.SetObjectAsJson("acerrors", messages);
                return(RedirectToAction("Activity", new{ id = pid }));
            }
        }
Esempio n. 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Acomment acomment = db.Acomment.Find(id);

            db.Acomment.Remove(acomment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
 public ActionResult Edit([Bind(Include = "id,answer_id,body,user_id")] Acomment acomment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(acomment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.answer_id = new SelectList(db.Answer, "id", "body", acomment.answer_id);
     ViewBag.user_id   = new SelectList(db.AppUser, "id", "name", acomment.user_id);
     return(View(acomment));
 }
Esempio n. 4
0
        // GET: Acomments/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Acomment acomment = db.Acomment.Find(id);

            if (acomment == null)
            {
                return(HttpNotFound());
            }
            return(View(acomment));
        }
Esempio n. 5
0
        // GET: Acomments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Acomment acomment = db.Acomment.Find(id);

            if (acomment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.answer_id = new SelectList(db.Answer, "id", "body", acomment.answer_id);
            ViewBag.user_id   = new SelectList(db.AppUser, "id", "name", acomment.user_id);
            return(View(acomment));
        }
Esempio n. 6
0
        public ActionResult CreateAnswerComment(int qid, int aid)
        {
            var cookieValue = Request.Cookies["userId"] == null ? "" : Request.Cookies["userId"].Value.ToString();

            if (cookieValue != "")
            {
                var userId   = int.Parse(cookieValue);
                var acomment = new Acomment();
                acomment.answer_id = aid;
                acomment.body      = Request.Form["aCommentBody"];
                acomment.user_id   = userId;
                db.Answer.Find(aid).Acomment.Add(acomment);
                db.SaveChanges();
                return(RedirectToAction("ShowQandA", new { id = qid, ShowComment = true }));
            }
            return(RedirectToAction("LogIn"));
        }