public virtual PartialViewResult Delete()
        {
            var deleteCommentId = FullContext.Value.EntityId.Value;
            var commentsTarget  = FullContext.GetCommentsTarget();
            var targetEntityId  = commentsTarget.EntityId.Value;

            var comment = _commentsService.Get(deleteCommentId);

            if (!_commentsService.CanDelete(comment, _intranetMemberService.GetCurrentMemberId()))
            {
                return(OverView(comment.ActivityId));
            }

            var command = new RemoveCommentCommand(FullContext, deleteCommentId);

            _commandPublisher.Publish(command);

            switch (commentsTarget.Type.ToInt())
            {
            case int type
                when ContextExtensions.HasFlagScalar(type, ContextType.Activity | ContextType.PagePromotion):
                var activityCommentsInfo = GetActivityComments(targetEntityId);

                return(OverView(activityCommentsInfo));

            default:
                return(OverView(comment.ActivityId));
            }
        }
Esempio n. 2
0
        public BroadcastResult Handle(RemoveCommentCommand command)
        {
            _commentsService.Delete(command.CommentId);
            UpdateCache(command.TargetType, command.TargetId);

            return(BroadcastResult.Success);
        }
Esempio n. 3
0
        public async Task <CommentsOverviewModel> Delete(Guid targetId, IntranetEntityTypeEnum targetType, Guid commentId)
        {
            var comment = await _commentsService.GetAsync(commentId);

            if (!_commentsService.CanDelete(comment, await _intranetMemberService.GetCurrentMemberIdAsync()))
            {
                return(await _commentsHelper.OverViewAsync(comment.ActivityId));
            }

            var command = new RemoveCommentCommand(targetId, targetType, commentId);

            _commandPublisher.Publish(command);

            switch (targetType)
            {
            case IntranetEntityTypeEnum type
                when type.Is(IntranetEntityTypeEnum.News, IntranetEntityTypeEnum.Social, IntranetEntityTypeEnum.Events):
                var activityCommentsInfo = GetActivityComments(targetId);

                return(await _commentsHelper.OverViewAsync(activityCommentsInfo.Id, activityCommentsInfo.Comments, activityCommentsInfo.IsReadOnly));

            default:
                return(await _commentsHelper.OverViewAsync(comment.ActivityId));
            }
        }
Esempio n. 4
0
        public async Task <CommandResult> Handle(RemoveCommentCommand request, CancellationToken cancellationToken)
        {
            Post post = await _postRepository.GetByIdAsync(request.PostId);

            bool isValidPost = await CanModifyPost(post);

            if (!isValidPost)
            {
                return(FailureDueToPostNotFound());
            }

            Comment comment = post.FindCommentById(request.CommentId);

            post.RemoveComment(comment);
            if (!post.IsValid)
            {
                return(FailureDueToEntityStateInconsistency(post));
            }

            await _commentRepository.RemoveAsync(comment);

            await _postRepository.UpdateAsync(post);

            return(await CommitAndPublishDefaultAsync());
        }
Esempio n. 5
0
        public BroadcastResult Handle(RemoveCommentCommand command)
        {
            var commentsTarget = command.Context.GetCommentsTarget();

            _commentsService.Delete(command.CommentId);
            UpdateCache(commentsTarget.Type, commentsTarget.EntityId.Value);

            return(BroadcastResult.Success);
        }
Esempio n. 6
0
        public async Task <IActionResult> RemoveCommentAsync(Guid id, Guid commentId)
        {
            RemoveCommentCommand command = new RemoveCommentCommand
            {
                PostId    = id,
                CommentId = commentId
            };

            return(await CreateCommandResponse(command));
        }
 public Task <bool> Handle(RemoveCommentCommand request, CancellationToken cancellationToken)
 {
     if (!request.IsValid())
     {
         NotifyValidationErrors(request);
         return(Task.FromResult(false));
     }
     _commentRepository.Remove(request.CommentId);
     if (Commit())
     {
         _bus.RaiseEvent(new CommentRemovedEvent(request.CommentId));
     }
     return(Task.FromResult(true));
 }
Esempio n. 8
0
        public async Task <IActionResult> RemoveComment([FromQuery] GuidRequest commentId)
        {
            var identifier = User.GetUserId();

            var command = new RemoveCommentCommand
            {
                Comment      = commentId,
                LoggedUserId = identifier
            };

            await _mediator.Send(command);

            return(NoContent());
        }
Esempio n. 9
0
        public async Task <IActionResult> RemoveComment(long id)
        {
            var query  = new RemoveCommentCommand(id);
            var result = await _mediator.Send(query);

            switch (result)
            {
            case ResultStatus.NotFound:
                return(Error(new { info = "اطلاعات بدرستی وارد نشده است." }));

            case ResultStatus.Success:
                return(Success());

            case ResultStatus.Error:
                return(Error(new { info = "خطایی رخ داده است" }));

            default:
                return(Error(new { info = "خطایی رخ داده است" }));
            }
        }
Esempio n. 10
0
        public async Task <Response <bool> > Handle(RemoveCommentCommand request, CancellationToken cancellationToken)
        {
            var comment = await commentRepo.GetCommentAsync(request.CommentId);

            if (comment == null)
            {
                return(Response.Fail <bool>("کامنت مورد نظر یافت نشد", StatusCodeEnum.NOTFUOUND));
            }
            if (comment.senderId == request.Userid)
            {
                await commentRepo.Remove(comment);

                return(Response.Ok());
            }
            var IsDelete = await RemoveCommenIfUserIsAdmin(request.Roles, comment);

            if (IsDelete)
            {
                return(Response.Ok());
            }
            return(Response.Fail <bool>("شما مجاز به انجام این کار نیستید", StatusCodeEnum.NOTFUOUND));
        }
Esempio n. 11
0
        public void Remove(int id)
        {
            var removeCommand = new RemoveCommentCommand(id);

            Bus.SendCommand(removeCommand);
        }