public async Task <Comment> SwitchReaction(int id, string userId, CommentReactionType type) { var comment = await _commentRepo.GetOneWithSubComment(c => c.Id == id); var isLiked = await CheckIfUserLiked(id, userId); comment.Like = isLiked ? comment.Like - 1 : comment.Like + 1; await _commentReactionService.SwitchReaction(id, userId, type); return(comment); }
public async Task SwitchReaction(int commentId, string userId, CommentReactionType type) { var existingReaction = await _commentReactionRepo.GetOneByCondition(r => r.CommentId == commentId && r.UserId == userId); if (existingReaction != null) { _commentReactionRepo.Remove(existingReaction); return; } var commentReaction = new CommentReaction() { UserId = userId, CommentId = commentId, Type = type, }; await _commentReactionRepo.Add(commentReaction); }
/// <summary> /// Add reaction to the last comment /// </summary> /// <param name="teamProjectName"></param> /// <param name="workItemID"></param> /// <param name="reactionType"></param> private static void AddReactionToLastComment(string teamProjectName, int workItemID, CommentReactionType reactionType) { CommentList comments = WitClient.GetCommentsAsync(teamProjectName, workItemID).Result; var reaction = WitClient.CreateCommentReactionAsync(teamProjectName, workItemID, comments.Comments.ElementAt(0).Id, reactionType).Result; Console.WriteLine("{0} - {1}\n", reaction.Type, reaction.Count); }