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

            var command = new AddLikeCommand(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 <IHttpActionResult> AddLike([FromUri] Guid entityId, [FromUri] IntranetEntityTypeEnum entityType)
        {
            if (!await CanAddRemoveLikeAsync(entityId, entityType))
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }

            var command = new AddLikeCommand(entityId, entityType, await _intranetMemberService.GetCurrentMemberIdAsync());

            _commandPublisher.Publish(command);

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

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

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

                return(Ok(activityLikeInfo.Likes));

            default:
                throw new IndexOutOfRangeException();
            }
        }
示例#3
0
        public async Task <IActionResult> AddLikeAsync(Guid id)
        {
            AddLikeCommand command = new AddLikeCommand
            {
                PostId = id
            };

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

            bool canModify = await CanModifyPost(post);

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

            PostLike postLike = new PostLike(_currentProfileId);

            post.AddLike(postLike);
            if (!post.IsValid)
            {
                return(FailureDueToEntityStateInconsistency(post));
            }

            await _postRepository.UpdateAsync(post);

            return(await CommitAndPublishDefaultAsync());
        }
示例#5
0
 public AddLikeOperation(AddLikeCommand command)
 {
     _command = command;
 }