public ActionResult AddComment(AddCommentViewModel model) { int userId = _accountService.GetUserByLogin(User.Identity.Name).UserId; _postService.AddComment(model.ToBllComment(userId, User.Identity.Name)); return(RedirectToAction("LoadMoreComment", new { page = 0, id = model.PostId })); }
public IActionResult addComment(int id, string comment) { _postService.AddComment(id, new Models.Comment { PostId = id, Content = comment }); return(new RedirectToActionResult("Detail", "Post", new { id = id })); }
public CommentViewModel AddComment(CommentViewModel viewModel) { Comment model = new Comment(); model.UpdateComment(viewModel); var res = _postService.AddComment(model); return(Mapper.Map <CommentViewModel>(res)); }
public IActionResult AddComment(string blogId, [FromBody] Comment comment) { var newComment = _postService.AddComment(blogId, comment); if (newComment == null) { return(NotFound($"No post found with id {blogId}")); } return(Ok(comment)); }
public async Task <IActionResult> AddComment(CommentViewModel model) { SetIsAuth(); Comment c = await postService.AddComment(Int32.Parse(Request.Cookies["user"]), model.PostId, model.Text); if (c != null) { return(Json(new { success = true, c.User.Avatar, c.User.Email, Date = c.Date.ToString("g"), c.Text })); } return(BadRequest()); }
public virtual ActionResult Create(AddCommentViewModel commentViewModel) { if (ModelState.IsValid) { _postService.AddComment(commentViewModel.PostId, commentViewModel.Name, commentViewModel.Comment); } else { TempData["comment"] = ViewData.ModelState; } return(new RedirectResult(Request.Headers["Referer"])); }
public async Task <IActionResult> AddComment([FromBody] CommentDto comment) { try { var id = await _service.AddComment(comment); return(Ok(id)); } catch (BussinessException ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> AddComment([Bind("CommentId,Content,CreateAt,PostId")] Comment comment) { if (ModelState.IsValid) { Post post = await _postService.GetPostById(comment.PostId); if (post != null) { await _postService.AddComment(post, comment); return(RedirectToAction("Index", new { newComment = true })); } } return(View()); }
public virtual object AddComment(Area areaInput, PostBase postBaseInput, Comment commentInput, UserBase userBaseInput, UserBase currentUser, bool?remember, bool?subscribe) { if (site.CommentingDisabled) { return(null); } Area area = areaService.GetArea(areaInput.Name); if (area == null || area.CommentingDisabled) { return(null); } Post post = postService.GetPost(area, postBaseInput.Slug); if (post == null || post.CommentingDisabled) { return(null); } ValidationStateDictionary validationState; Comment newComment; postService.AddComment(area, post, commentInput, currentUser ?? userBaseInput, subscribe.HasValue && subscribe.Value, out validationState, out newComment); if (!validationState.IsValid) { ModelState.AddModelErrors(validationState); return(Item(areaInput, postBaseInput)); } //todo: (nheskew) move into an action filter? if (remember != null && (bool)remember) { Response.Cookies.SetAnonymousUser(userBaseInput); } else if (currentUser == null && Request.Cookies.GetAnonymousUser() != null) { Response.Cookies.ClearAnonymousUser(); } return(new RedirectResult(newComment.State != EntityState.PendingApproval ? Url.Comment(post, newComment) : Url.CommentPending(post, newComment))); }
public IActionResult AddComment(int postId, string comment) { _postService.AddComment(comment, postId); return(ShowPost(postId)); }
private IActionResult AddComment([FromBody] PostDTO PostDTO, string username, string text) { return(Ok(_postService.AddComment(PostDTO, username, text))); }
public void Post(string postId, [FromBody] Comment comment) { _service.AddComment(postId, comment); }
public void GivenAValidPost_WhenIAddAComment_AndTheDatabaseIsNotAvailable_ThenAnMBlogExceptionIsThrown() { _postRepository.Setup(p => p.AddComment(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>())).Throws <Exception>(); Assert.Throws <MBlogException>(() => _postService.AddComment(1, "name", "comment")); }