public ActionResult CreateComment(int?id, string description) { string message = ""; string status = ""; if (ModelState.IsValid) { var comment = new Comment(); comment.UserID = (int)Session["UserID"]; comment.PostID = id.Value; comment.Description = description; commentRepository.CreateComment(comment); ModelState.Clear(); message = "comment successfully inserted"; status = "success"; } else { message = "Error creating comment"; status = "danger"; } TempData["message"] = message; TempData["status"] = status; return(RedirectToAction("Show", "Post", new { id = id })); }
public IActionResult Create([Bind("CommentId,Content")] Comment comment, int postId) { if (ModelState.IsValid) { string name = User.Identity.Name; comment = repo.CreateComment(comment, name, postId); return(RedirectToAction("Details", "Posts", new { id = postId })); } return(View(comment)); }
public Comment CreateComment([FromBody] Comment newComment) { if (ModelState.IsValid) { var user = HttpContext.User; newComment.AuthorId = user.Identity.Name; return(_db.CreateComment(newComment)); } return(null); }
public IActionResult Create(Comment comment) { if (ModelState.IsValid) { comment.CreatedDate = DateTime.Now; comment.BlogID = comment.ID; comment.ID = 0; CommentRepository.CreateComment(comment); return(RedirectToAction("Create", "Comments", comment.BlogID)); } SetBlogToComment(comment.ID); return(View(comment)); }
public ActionResult CreateComment(ApiComment comment) { try { var result = CommentRepository.CreateComment(comment.Cast()); if (result == null) { return(StatusCode(500)); } return(Ok(new ApiComment(result))); } catch { return(StatusCode(500)); } }
public void CreateComment(CommentDto dto) { try { _logger.Info("UseCase : {0}", "start create comment"); var comment = new Comment(dto.ContentComment, dto.OwnerComment, dto.PageId) { }; _logger.Info("UseCase : {0}", "adding to repository"); _commentRepo.CreateComment(comment); } catch (Exception ex) { _logger.Error(ex.Message); } }
public ActionResult Create([FromForm] Comment comment) { try { comment.TimeStamp = DateTime.Now; _commentRepository.CreateComment(comment); var post = _postRepository.GetPost(comment.PostId); post.Comments.Add(comment.CommentId); _postRepository.UpdatePost(post.PostId, post); return(RedirectToAction("Index", "Home")); } catch { return(View()); } }
public IActionResult CreateComment(Comment c) { return(new OkObjectResult(_commentRepo.CreateComment(c))); }
public void CreateComment(CommentModel newComment) { _commentRepository.CreateComment(newComment); }