public ActionResult CommentByPost(int id) { ViewBag.ActiveUserRole = GetActiveUserRole(); var allComments = _commentService.GetAll(); var comments = _mapper.Map <IEnumerable <CommentViewModel> >(allComments); if (id != null && id != 0) { comments = comments.Where(x => x.PostViewModel.Id == id); } var postModel = _postService.GetById(id); var postViewModel = _mapper.Map <PostViewModel>(postModel); CommentsPost commentsList = new CommentsPost { Comments = comments, PostViewModel = postViewModel }; ViewBag.ActiveUserRole = GetActiveUserRole(); return(View(commentsList)); }
public ActionResult CommentByPost(int id) { var allComments = _commentService.GetAll(); var comments = _mapper.Map <IEnumerable <CommentViewModel> >(allComments); if (id != null && id != 0) { comments = comments.Where(x => x.PostViewModel.Id == id); } //var allPosts = _postService.GetAll(); //var posts = _mapper.Map<IEnumerable<PostViewModel>>(allPosts); var postModel = _postService.GetById(id); var postViewModel = _mapper.Map <PostViewModel>(postModel); CommentsPost commentsList = new CommentsPost { Comments = comments, //Posts = new SelectList(posts, "Id", "Title ") PostViewModel = postViewModel }; return(View(commentsList)); }