Esempio n. 1
0
 public ActionResult Create(Comment comment)
 {
     if (ModelState.IsValid) {
         _commentRepository.InsertOrUpdate(comment);
         _commentRepository.Save();
         return RedirectToAction("Index");
     } else {
         ViewBag.PossibleArticles = _articleRepository.All;
         return View();
     }
 }
Esempio n. 2
0
 public void InsertOrUpdate(Comment comment)
 {
     if (comment.Id == default(int))
     {
         // New entity
         _context.Comments.Add(comment);
     }
     else
     {
         // Existing entity
         _context.Entry(comment).State = EntityState.Modified;
     }
 }
Esempio n. 3
0
        public ActionResult Comment(Comment model)
        {
            var article = _articleRepository.Find(model.ArticleId);

            model.IPAddress = Request.UserHostAddress;
            model.CreatedOn = DateTime.UtcNow;

            ModelState.Remove("CreatedOn");
            ModelState.Remove("IpAddress");

            TryUpdateModel(model);

            if (ModelState.IsValid && Utilities.IsCaptchaValid(Request.Form))
            {
                _commentRepository.InsertOrUpdate(model);

                _commentRepository.Save();
            }

            Response.Redirect("~/" + article.URLTo + "#comments");
            return new EmptyResult();
        }