Exemplo n.º 1
0
 public ActionResult AddComment(Comment newComment, string Slug)
 {
     if (ModelState.IsValid) {
         newComment.CreatedDate = System.DateTimeOffset.Now;
         newComment.IsRemoved = false;
         newComment.RemovedDate = null;
         newComment.RemovedBy = "";
         newComment.AuthorId = User.Identity.GetUserId();
         db.Comments.Add(newComment);
         db.SaveChanges();
     }
     return RedirectToAction(Slug, "Post");
 }
Exemplo n.º 2
0
        public ActionResult EditComment(Comment editComment, string Slug)
        {
            if (ModelState.IsValid) {
                // the Comments refers to the Model IdentityModels - public DbSet<Comment> Comments { get; set; }.
                if (!db.Comments.Local.Any(c => c.Id == editComment.Id))
                    db.Comments.Attach(editComment);

                db.Entry(editComment).Property(p => p.Body).IsModified = true;
                db.Entry(editComment).Property(p => p.UpdateReason).IsModified = true;
                db.Entry(editComment).Property(p => p.UpdatedBy).IsModified = true;
                editComment.UpdatedDate = System.DateTimeOffset.Now;
                db.SaveChanges();
            }
            return RedirectToAction(Slug, "Post");
        }
Exemplo n.º 3
0
 public ActionResult CreateComment(Comment Comment,string Slug)
 {
     if (ModelState.IsValid)
     {
         Comment.Created = System.DateTimeOffset.Now;
         Comment.AuthorId = User.Identity.GetUserId();
         Comment.Updated = null;
         db.Comments.Add(Comment);
         db.SaveChanges();
     }
     return RedirectToAction("DetailsU", "BlogPosts", new {Slug = Slug});
 }