Beispiel #1
0
        public void Process(Comment source, CommentViewModel destination, ResolutionContext context)
        {
            try
            {
                User currentUser = Feature.CurrentUser(httpContextAccessor, userRepository);

                User author = userRepository.GetById(ObjectId.Parse(source.AuthorId));

                destination.AuthorName   = $"{author?.FirstName} {author?.LastName}";
                destination.AuthorAvatar = author?.AvatarHash;
                destination.AuthorEmail  = author?.Email;
                destination.RepliesCount = replyCommentRepository.GetAll().Where(x => x.Status == ItemStatus.Active && x.ParentId == source.OId).Count();

                IQueryable <UpVote> listUpVote = upVoteRepository.GetAll().Where(x => x.ObjectVoteId == source.OId && x.IsDeleted == false);
                destination.UpvoteCount = listUpVote.Count();

                destination.IsVoteByCurrent = (listUpVote.FirstOrDefault(x => x.UpVoteBy == currentUser.OId) != null);

                IQueryable <DownVote> listDownVote = downVoteRepository.GetAll().Where(x => x.ObjectVoteId == source.OId && x.IsDeleted == false);
                destination.DownvoteCount       = listDownVote.Count();
                destination.IsDownVoteByCurrent = listDownVote.FirstOrDefault(x => x.DownVoteBy == currentUser.OId) != null;
            }
            catch (Exception)
            {
                Console.WriteLine("Lỗi convert action ");
            }
        }
Beispiel #2
0
        public string RemoveViolenceReply()
        {
            var comments       = replyCommentRepository.GetAll().Where(x => x.Status == ItemStatus.Active);
            var deletedComment = 0;

            foreach (var comment in comments)
            {
                try
                {
                    var isViolence = commentService.IsViolenceReply(comment.OId);
                    if (isViolence == true)
                    {
                        var notificationDetail = new Noftication()
                        {
                            AuthorId        = "60b5f2623d52db390d464e3e",
                            OwnerId         = "60b5f2623d52db390d464e3e",
                            ObjectId        = comment.OId,
                            ObjectThumbnail = comment.Content
                        };

                        fcmRepository.PushNotify(comment.AuthorId,
                                                 notificationDetail,
                                                 NotificationContent.ApproveReplyReportNotification,
                                                 $"Phản hồi của bạn đã bị xóa bởi vì vi phạm quy định của chúng tôi. ").ConfigureAwait(true);

                        deletedComment++;
                        comment.Status = ItemStatus.Blocked;
                        replyCommentRepository.Update(comment, comment.Id);

                        var report = new Report()
                        {
                            ObjectId    = comment.OId,
                            ObjectType  = Feature.GetTypeName(comment),
                            CreatedDate = DateTime.Now,
                            IsApproved  = true,
                            ApprovedBy  = "60b5f2623d52db390d464e3e",
                            ApproveDate = DateTime.Now,
                            AuthorId    = comment.AuthorId,
                            Reason      = new System.Collections.Generic.List <string>()
                            {
                                "606bc1ddd01f5aa1a3e282f5"
                            }
                        };

                        reportRepository.Add(report);
                    }
                }
                catch (Exception)
                {
                    //Do nothing
                }
            }

            return($"Task complete with {deletedComment} reply comments deleted at {DateTime.Now.ToUniversalTime()}");
        }
Beispiel #3
0
        public TableResultJson <ReplyCommentViewModel> GetReplyCommentPaged(TableRequest request)
        {
            var dataSource          = replyCommentRepository.GetAll().OrderByDescending(x => x.CreatedDate).ToList();
            var dataSourceViewModel = (mapper.Map <List <ReplyCommentViewModel> >(dataSource)).AsEnumerable();

            if (request.columns[1].search != null)
            {
                var _value1 = request.columns[1].search.value;
                if (!string.IsNullOrEmpty(_value1))
                {
                    dataSourceViewModel = dataSourceViewModel.Where(x => x.OId.Contains(_value1));
                }
            }

            if (request.columns[2].search != null)
            {
                var _value2 = request.columns[2].search.value;
                if (!string.IsNullOrEmpty(_value2))
                {
                    dataSourceViewModel = dataSourceViewModel.Where(x => x.AuthorName.Contains(_value2));
                }
            }

            if (request.columns[3].search != null)
            {
                if (!string.IsNullOrEmpty(request.columns[3].search.value))
                {
                    var dt = DateTime.TryParseExact(request.columns[3].search.value, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var datetime);
                    if (dt)
                    {
                        dataSourceViewModel = dataSourceViewModel.Where(x => x.CreatedDate.Value.Date == datetime);
                    }
                }
            }

            if (request.columns[8].search != null)
            {
                var _value4 = request.columns[8].search.value;
                if (!string.IsNullOrEmpty(_value4))
                {
                    dataSourceViewModel = dataSourceViewModel.Where(x => x.Content.Contains(_value4));
                }
            }

            var response = new TableResultJson <ReplyCommentViewModel>();

            response.draw            = request.draw;
            response.recordsFiltered = dataSourceViewModel.Count();
            dataSourceViewModel      = dataSourceViewModel.Skip(request.start).Take(request.length);
            response.data            = dataSourceViewModel.ToList();

            response.data.ForEach(x => { x.Index = response.data.IndexOf(x) + request.start + 1; });
            return(response);
        }