public void CreateComment(int postId, string commentText) { PostComment comment = new PostComment(); comment.BlogpostId = postId; comment.DateOfComment = DateTime.Now; comment.TextComment = commentText; comment.UserId = Convert.ToInt32(User.Identity.GetUserId()); CommentRepo.Save(comment); CommentRepo.Commit(); }
public ActionResult <CommentViewModel> Post([FromBody] CommentCreationViewModel model) { var creationTime = ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds(); var comm = new Model.Comment { BlogId = model.BlogId, UserId = NVLInt64(HttpContext.User.Identity.Name, 0), Content = model.Content, CreationTime = creationTime, }; _commentRepository.Add(comm); _commentRepository.Commit(); return(_mapper.Map <Model.Comment, CommentViewModel>(comm)); }
public ActionResult Delete(string userName) { var user = Logic.Find(u => u.UserName == userName); IEnumerable <BlogPost> blogPosts = BlogRepo.Get(o => o.UserId == user.Id, null, "", 0, 0); IEnumerable <PostComment> comments = CommentRepo.Get(o => o.UserId == user.Id, null, "", 0, 0); foreach (var item in blogPosts) { IEnumerable <PostComment> commentsFor = CommentRepo.Get(o => o.BlogpostId == item.Id, null, "", 0, 0); foreach (var comment in commentsFor) { CommentRepo.Delete(comment.Id); } BlogRepo.Delete(item.Id); } foreach (var item in comments) { CommentRepo.Delete(item.Id); } CommentRepo.Commit(); Logic.Delete(user); return(RedirectToAction("Index")); }
public IActionResult OnPost() { var submitComment = new Comment() { PostId = NewComment.PostId, Name = NewComment.Name, EmailAddress = NewComment.EmailAddress, Content = NewComment.Content, CommentDate = DateTime.Now }; _commentRepo.Add(submitComment); _commentRepo.Commit(); ModelState.Clear(); NewComment = new CommentViewModel(); LoadPostAndComments(Slug); return(Page()); }