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)); }
public async Task <IEnumerable <ReportViewModel> > Approve(IEnumerable <string> ids) { List <Report> dataToApprove = new List <Report>(); foreach (string item in ids) { Report rp = await reportRepository.GetByIdAsync(ObjectId.Parse(item)); if (rp != null) { dataToApprove.Add(rp); } } User currentUser = Feature.CurrentUser(httpContextAccessor, userRepository); foreach (Report item in dataToApprove) { #region Find the same object var reportBuilders = Builders <Report> .Filter; var reportFilter = reportBuilders.Eq("object_id", item.ObjectId); var sameObjects = (await reportRepository.FindListAsync(reportFilter)).ToList(); sameObjects.ForEach(async x => { x.IsApproved = true; x.ModifiedDate = DateTime.Now; x.ApprovedBy = currentUser.OId; x.ApproveDate = DateTime.Now; await reportRepository.UpdateAsync(x, x.Id); }); #endregion if (item.ObjectType.Contains("Post")) { Post post = await postRepository.GetByIdAsync(ObjectId.Parse(item.ObjectId)); post.Status = ItemStatus.Deleted; post.ModifiedDate = DateTime.Now; await postRepository.UpdateAsync(post, post.Id); var user = await userRepository.GetByIdAsync(ObjectId.Parse(post.AuthorId)); if (user == null) { throw new Exception("Không tìm thấy người dùng. "); } var notificationDetail = new Noftication() { AuthorId = currentUser.OId, OwnerId = currentUser.OId, ObjectId = post.OId, ObjectThumbnail = post.Title }; await fcmRepository.PushNotify(post.AuthorId, notificationDetail, NotificationContent.ApprovePostReportNotification, $"Bài viết của bạn đã bị xóa bởi quản trị viên. "); //Báo cáo của bạn đã được duyệt. await fcmRepository.PushNotify(item.AuthorId, notificationDetail, NotificationContent.ApprovePostReportNotification, $"Báo cáo của bạn về bài viết của{user.FirstName} {user.LastName} đã được xem xét. "); } else if (item.ObjectType.Contains("ReplyComment")) { ReplyComment replyComment = await replyCommentRepository.GetByIdAsync(ObjectId.Parse(item.ObjectId)); replyComment.Status = ItemStatus.Deleted; replyComment.ModifiedDate = DateTime.Now; await replyCommentRepository.UpdateAsync(replyComment, replyComment.Id); var user = await userRepository.GetByIdAsync(ObjectId.Parse(replyComment.AuthorId)); if (user == null) { throw new Exception("Không tìm thấy người dùng. "); } var notificationDetail = new Noftication() { AuthorId = currentUser.OId, OwnerId = currentUser.OId, ObjectId = replyComment.OId, ObjectThumbnail = replyComment.Content }; //Báo cáo của bạn đã được duyệt. await fcmRepository.PushNotify(item.AuthorId, notificationDetail, NotificationContent.ApproveReplyReportNotification, $"Báo cáo của bạn về phản hồi của {user.FirstName} {user.LastName} đã được xem xét. "); await fcmRepository.PushNotify(replyComment.AuthorId, notificationDetail, NotificationContent.ApproveReplyReportNotification, $"Phản hồi của bạn đã bị xóa bởi quản trị viên. "); } else if (item.ObjectType.Contains("Comment")) { Comment comment = await commentRepository.GetByIdAsync(ObjectId.Parse(item.ObjectId)); comment.Status = ItemStatus.Deleted; comment.ModifiedDate = DateTime.Now; await commentRepository.UpdateAsync(comment, comment.Id); var user = await userRepository.GetByIdAsync(ObjectId.Parse(comment.AuthorId)); if (user == null) { throw new Exception("Không tìm thấy người dùng. "); } var notificationDetail = new Noftication() { AuthorId = currentUser.OId, OwnerId = currentUser.OId, ObjectId = comment.OId, ObjectThumbnail = comment.Content }; //Báo cáo của bạn đã được duyệt. await fcmRepository.PushNotify(item.AuthorId, notificationDetail, NotificationContent.ApproveCommentReportNotification, $"Báo cáo của bạn về bình luận của {user.FirstName} {user.LastName} đã được xem xét."); await fcmRepository.PushNotify(comment.AuthorId, notificationDetail, NotificationContent.ApproveCommentReportNotification, $"Bình luận của bạn đã bị xóa bởi quản trị viên. "); } } return(mapper.Map <IEnumerable <ReportViewModel> >(dataToApprove)); }