Esempio n. 1
0
        public JsonResult ShowPost(int postId)
        {
            bool status        = false;
            var  postViewModel = new PostViewModel();

            try
            {
                var post = postService.GetById(postId);
                postViewModel          = Mapper.Map <PostViewModel>(post);
                postViewModel.Comments = commentService.GetByPostId(postId);
                postViewModel.Likes    = likeService.GetByPostId(postId);
                foreach (var j in postViewModel.Comments)
                {
                    // Commented by
                    j.User = userService.GetById(Convert.ToInt32(j.CreatedBy));
                }
                // Auth
                postViewModel.User = userService.GetById(Convert.ToInt32(post.CreatedBy));
                status             = true;
            }
            catch (Exception)
            {
                status = false;
            }
            return(Json(new { data = postViewModel, status = status }, JsonRequestBehavior.AllowGet));
        }