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(); } }
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(); } }
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()); }
public AddLikeOperation(AddLikeCommand command) { _command = command; }