コード例 #1
0
        public async Task <PostVM> CreateComment(CreateCommentRequest request, ApplicationUser applicationUser)
        {
            var post = await _context.Posts.Where(x => x.PostID == request.PostID).FirstOrDefaultAsync();

            if (post == null)
            {
                return(null);
            }
            // Khởi tạo và add commnet vào bảng commnet
            var commnet = new Comment()
            {
                Content     = request.Content,
                DateCreated = DateTime.Now,
                Author      = applicationUser.FullName,
                Parent      = 0,
                Id          = applicationUser.Id,
                PostID      = request.PostID
            };

            _context.Comments.Add(commnet);
            await _context.SaveChangesAsync();

            // Xử lý post view model hiển thị về cho user
            var postVM = _public_post_service.PublicDeatilPost(request.PostID);

            return(await postVM);
        }
コード例 #2
0
        public async Task <IActionResult> Detail(int id)
        {
            var result = await _public_post_service.PublicDeatilPost(id);

            if (result == null)
            {
                return(BadRequest("Bai post khong ton tai"));
            }
            return(Ok(result));
        }