Example #1
0
        public async Task <ReplyCommentViewModel> GetReplyCommentById(string id)
        {
            var replyComment = await replyCommentRepository.GetByIdAsync(ObjectId.Parse(id));

            var result = mapper.Map <ReplyCommentViewModel>(replyComment);

            return(result);
        }
Example #2
0
        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));
        }