Esempio n. 1
0
        public async Task <PostViewModel> ModifiedPostStatus(ModifedPostStatusRequest request)
        {
            var post = await postRepository.GetByIdAsync(ObjectId.Parse(request.PostId));

            if (post == null)
            {
                throw new Exception("Không tìm thấy bài viết. ");
            }
            post.Status = request.Status;
            await postRepository.UpdateAsync(post, post.Id);

            //Modified comment
            var commentBuilder = Builders <Comment> .Filter;
            var commentFilter  = commentBuilder.Eq("post_id", post.OId);
            var comments       = await commentRepository.FindListAsync(commentFilter);

            comments.ForEach(async x =>
            {
                x.Status = request.Status;
                await commentRepository.UpdateAsync(x, x.Id);
                var replyFilter = Builders <ReplyComment> .Filter.Eq("parent_id", x.OId);

                var replies = await replyCommentRepository.FindListAsync(replyFilter);
                replies.ForEach(async y =>
                {
                    y.Status = request.Status;
                    await replyCommentRepository.UpdateAsync(y, y.Id);
                });
            });

            return(mapper.Map <PostViewModel>(post));
        }
Esempio n. 2
0
        public async Task <IActionResult> ModifiedPostStatus(ModifedPostStatusRequest request)
        {
            var data = await postService.ModifiedPostStatus(request);

            return(Ok(new ApiOkResponse(data)));
        }