示例#1
0
        public virtual PartialViewResult RemoveLike()
        {
            var likeTarget     = FullContext.Value;
            var targetEntityId = likeTarget.EntityId.Value;

            var command = new RemoveLikeCommand(FullContext, _intranetMemberService.GetCurrentMemberId());

            _commandPublisher.Publish(command);

            switch (likeTarget.Type.ToInt())
            {
            case (int)Comment:
                return(Likes(_likesService.GetLikeModels(targetEntityId), targetEntityId));

            case (int)ContentPage:
                return(Likes(_likesService.GetLikeModels(targetEntityId), targetEntityId, showTitle: true));

            case int type when HasFlagScalar(type, Activity | PagePromotion):
                var activityLikeInfo = GetActivityLikes(targetEntityId);

                return(Likes(activityLikeInfo.Likes, activityLikeInfo.Id, activityLikeInfo.IsReadOnly, showTitle: HasFlagScalar(type, PagePromotion)));

            default:
                throw new IndexOutOfRangeException();
            }
        }
示例#2
0
        public async Task <IEnumerable <LikeModel> > RemoveLike(Guid entityId, IntranetEntityTypeEnum entityType)
        {
            if (await CanAddRemoveLikeAsync(entityId, entityType))
            {
                var command = new RemoveLikeCommand(entityId, entityType, await _intranetMemberService.GetCurrentMemberIdAsync());
                _commandPublisher.Publish(command);
            }

            switch (entityType)
            {
            case IntranetEntityTypeEnum.Comment:
                return(await _likesService.GetLikeModelsAsync(entityId));

            case IntranetEntityTypeEnum.ContentPage:
                return(await _likesService.GetLikeModelsAsync(entityId));

            case IntranetEntityTypeEnum type when type.Is(IntranetEntityTypeEnum.News, IntranetEntityTypeEnum.Social, IntranetEntityTypeEnum.Events):
                var activityLikeInfo = GetActivityLikes(entityId);

                return(activityLikeInfo.Likes);

            default:
                throw new IndexOutOfRangeException();
            }
        }
示例#3
0
        public BroadcastResult Handle(RemoveLikeCommand command)
        {
            var likeTargetEntityId = command.EntityId;

            _likesService.Remove(command.Author, likeTargetEntityId);
            UpdateCache(command.EntityType, likeTargetEntityId);

            return(BroadcastResult.Success);
        }
示例#4
0
        public async Task <IActionResult> RemoveLikeAsync(Guid id)
        {
            RemoveLikeCommand command = new RemoveLikeCommand
            {
                PostId = id
            };

            return(await CreateCommandResponse(command));
        }
示例#5
0
        public BroadcastResult Handle(RemoveLikeCommand command)
        {
            var likeTarget         = command.Context.Value;
            var likeTargetEntityId = likeTarget.EntityId.Value;

            _likesService.Remove(command.Author, likeTargetEntityId);
            UpdateCache(likeTarget.Type, likeTargetEntityId);

            return(BroadcastResult.Success);
        }
        public async Task <CommandResult> Handle(RemoveLikeCommand request, CancellationToken cancellationToken)
        {
            Post post = await _postRepository.GetByIdAsync(request.PostId);

            bool canModify = await CanModifyPost(post);

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

            PostLike like = post.FindLikeByProfileId(_currentProfileId);

            post.RemoveLike(like);
            if (!post.IsValid)
            {
                return(FailureDueToEntityStateInconsistency(post));
            }

            await _postRepository.UpdateAsync(post);

            return(await CommitAndPublishDefaultAsync());
        }