public async Task <IActionResult> LeaveCommentAsync([FromBody] CommentDetailsViewModel model) { try { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(StatusCode(StatusCodes.Status422UnprocessableEntity)); } var endPoint = await BusConfigurator.GetEndPointAsync(RabbitMqConstants.ArticleWriteServiceQueue); await endPoint.Send <IInsertCommentCommand>(new { model.AddedBy, model.AddedByEmail, model.ArticleId, model.CategoryId, model.Body }); return(Accepted()); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IActionResult LeaveComment(CommentDetailsViewModel model) { var comment = _mapper.Map <Comment>(model); comment.AddedDate = DateTime.Now; comment.AddedByIp = _accessor.HttpContext.Connection.RemoteIpAddress.ToString(); _articlesRepository.InsertComment(comment); _unitOfWork.Commit(); return(RedirectToAction(nameof(this.ShowArticle), new { id = model.ArticleId })); }
public async Task <ActionResult> AddComment(CommentDetailsViewModel viewModel) { if (!ModelState.IsValid) { return(RedirectToAction("Details", new { viewModel.Comment.Id })); } viewModel.PostCommentModel.ParentCommentId = viewModel.Comment.Id; await Mediator.Send(new AddCommentCommand(viewModel.PostCommentModel)); return(RedirectToAction("Details", new { id = viewModel.Comment.Id })); }
// GET: Administration/Comments/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CommentDetailsViewModel commentVM = this.commentServices.CreatDetailsViewModelFromCommentId(id); if (commentVM == null) { return(HttpNotFound()); } return(View(commentVM)); }
public ActionResult ViewPostComments(int postId, int?page) { int pageSize = 2; int pageNumber = (page ?? 1); ViewBag.PostId = postId; var userId = User.Identity.GetUserId(); var model = commentService.GgetCommentsByPostId(postId, userId); CommentDetailsViewModel vm = new CommentDetailsViewModel(); vm.Comments = model.ToPagedList(pageNumber, pageSize); vm.isUserActive = userId; return(PartialView("_ViewPostComments", vm)); }
public async Task <ViewResult> Details(int id, PagingParams pagingParams) { var commentModel = await Mediator.Send(new GetCommentQuery(id)); var board = await Mediator.Send(new GetBoardQuery(commentModel.BoardId)); GetArticleModel parentArticle; try { parentArticle = await Mediator.Send(new GetArticleQuery(commentModel.ParentArticleId)); } catch (NotFoundException) { parentArticle = new GetArticleModel(); } GetCommentModel parentComment; try { parentComment = await Mediator.Send(new GetCommentQuery(commentModel.ParentCommentId)); } catch (NotFoundException) { parentComment = new GetCommentModel(); } var childComments = await Mediator.Send(new GetCommentsByIdsQuery(commentModel.CommentIds, pagingParams)); var user = await Mediator.Send(new GetPublicUserQuery(commentModel.UserId)); GetPrivateUserModel privateUser = null; try { privateUser = await Mediator.Send(new GetAuthenticatedUserQuery()); } catch (NotFoundException) { } catch (UnauthorizedException) { } var loggedIn = privateUser != null && privateUser.Id != 0; var savedComment = loggedIn ? privateUser.SavedComments.Contains(id) : false; var model = new CommentDetailsViewModel { Board = board, ChildCommentPage = new FrontendPage <GetCommentModel>(childComments), Comment = commentModel, LoggedIn = loggedIn, ParentArticle = parentArticle, ParentComment = parentComment, PostCommentModel = new PostCommentModel(), User = user, UserSavedComment = savedComment, UserWroteComment = commentModel.UserId == user.Id }; return(View(model)); }