Beispiel #1
0
 public TotalVotes(Guid userId, int symbolId, int count, VoteDirection myVoteDirection)
 {
     UserId          = userId;
     SymbolId        = symbolId;
     Count           = count;
     MyVoteDirection = myVoteDirection;
 }
Beispiel #2
0
 public Vote(Guid userId, int symbolId, VoteDirection direction, DateTime lastUpdated)
 {
     UserId      = userId;
     SymbolId    = symbolId;
     Direction   = direction;
     LastUpdated = lastUpdated;
 }
Beispiel #3
0
 internal Vote(int userId, VotableEntityType resourceType, int resourceId, VoteDirection direction)
 {
     UserId       = userId;
     ResourceType = resourceType;
     ResourceId   = resourceId;
     Direction    = direction;
 }
Beispiel #4
0
        public async Task <ActionResult> VoteOnComment(int commentId, VoteDirection vote)
        {
            var result = await commentVoter.Handle(new VoteOnCommentParams(commentId, vote, User !));

            return(result.Match <ActionResult>(
                       vote => Ok(vote),
                       fail => BadRequest(fail)
                       ));
        }
Beispiel #5
0
        /// <summary>
        /// Vote a definiton to be up or down.
        /// </summary>
        /// <param name="defId">The definiton id of the... definiton.</param>
        /// <param name="direction">The direction, either Up or Down</param>
        /// <returns>When awaited, returns a <see cref="VoteResponse"/>.</returns>
        /// <exception cref="VoteException">
        /// When the <see cref="VoteResponse.Status"/> is <see cref="VoteStatus.Error"/>.
        /// </exception>
        public async Task <VoteResponse> VoteOnDefinition(int defId, VoteDirection direction)
        {
            CheckDefinitionId(defId);
            var lowered = direction.ToString().ToLower();
            var result  = await Rest.ExecuteAsync <VoteResponse>(new RestRequest($"vote?defid={defId}&direction={lowered}")).ConfigureAwait(false);

            if (result.Status == VoteStatus.Error)
            {
                throw new VoteException($"An error occured while sending the vote request, the definiton id ({defId}) is probably wrong.");
            }
            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// Add a new vote to the counts.
        /// </summary>
        /// <param name="vote">The type of vote to add.</param>
        public void AddVote(VoteDirection vote)
        {
            switch (vote)
            {
            case VoteDirection.Up:
                Upvotes++;
                break;

            case VoteDirection.Down:
                Downvotes++;
                break;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Remove a vote from the couns.
        /// </summary>
        /// <param name="vote">The vote to remove.</param>
        public void RemoveVote(VoteDirection vote)
        {
            switch (vote)
            {
            case VoteDirection.Up:
                Upvotes--;
                break;

            case VoteDirection.Down:
                Downvotes--;
                break;
            }
        }
Beispiel #8
0
        public async Task Should_SaveVoteForUser(VoteDirection voteDirection)
        {
            string user1Id = (await TestUtil.CreateNewUser(AppTestSettings.Instance.TestDBConnectionString)).ToString();

            Symbol jpmSymbol = await _symbolRepo.GetSymbol("JPM");

            var voteCommand = new VoteCommand {
                SymbolId = jpmSymbol.Id, Direction = voteDirection
            };

            await SendVoteForCustomUser(voteCommand, user1Id);

            Dictionary <int, TotalVotes> voteData = await GetVoteData(user1Id, new int[] { jpmSymbol.Id });

            Assert.Single(voteData);
            Assert.True(voteData.ContainsKey(jpmSymbol.Id));

            var totalVotes = voteData[jpmSymbol.Id];

            Assert.Equal((int)voteDirection, totalVotes.Count);
            Assert.Equal(voteDirection, totalVotes.MyVoteDirection);
            Assert.Equal(jpmSymbol.Id, totalVotes.SymbolId);
            Assert.Equal(user1Id, totalVotes.UserId.ToString());
        }
Beispiel #9
0
 public Vote CreateForPost(User user, int postId, VoteDirection direction) => new Vote(user.Id, VotableEntityType.Post, postId, direction);
Beispiel #10
0
 public VoteOnPost(int postId, VoteDirection voteDirection)
 {
     PostId        = postId;
     VoteDirection = voteDirection;
 }
Beispiel #11
0
 public VoteOnCommentParams(int commentId, VoteDirection vote, User user)
 {
     CommentId = commentId;
     Vote      = vote;
     User      = user;
 }
Beispiel #12
0
 public VoteOnPostParams(int postId, VoteDirection vote, User user)
 {
     PostId = postId;
     Vote   = vote;
     User   = user;
 }
Beispiel #13
0
 /// <summary>
 /// Vote for an image. Send the same value again to undo a vote.
 /// </summary>
 /// <param name="albumId">The Id of the album to vote for</param>
 /// <param name="vote">The vote to give</param>
 public async Task <ImgurResponse <Boolean> > VoteOnGalleryAlbumAsync(string albumId, VoteDirection vote)
 {
     return(await VoteOnGalleryObjectAsync(albumId, true, vote));
 }
Beispiel #14
0
 /// <summary>
 /// Create a new vote view.
 /// </summary>
 /// <param name="resourceType">If its a post or comment.</param>
 /// <param name="resourceId">The ID of the resource.</param>
 /// <param name="direction">The direction of the vote.</param>
 public VoteView(VoteResourceType resourceType, int resourceId, VoteDirection direction)
 {
     ResourceType = resourceType;
     ResourceId   = resourceId;
     Direction    = direction;
 }
Beispiel #15
0
 /// <summary>
 /// Vote for an album. Send the same value again to undo a vote.
 /// </summary>
 /// <param name="imageId">The Id of the image to vote for</param>
 /// <param name="vote">The vote to give</param>
 public async Task <ImgurResponse <Boolean> > VoteOnGalleryImageAsync(string imageId, VoteDirection vote)
 {
     return(await VoteOnGalleryObjectAsync(imageId, false, vote));
 }
Beispiel #16
0
 public async Task <IActionResult> VoteOnPost(int postId, VoteDirection vote) =>
 (await mediator.Command(new VoteOnPostCommand(new VoteOnPost(postId, vote), User !)))
Beispiel #17
0
 public VotePayload(VoteDirection direction, int ratingShift)
 {
     this.Direction = direction;
     this.RatingShift = ratingShift;
 }
Beispiel #18
0
 public Vote CreateForComment(User user, int commentId, VoteDirection direction) => new Vote(user.Id, VotableEntityType.Comment, commentId, direction);
Beispiel #19
0
 public Vote Create(int id, int userId, VotableEntityType entityType, int entityId, VoteDirection direction) => new Vote(id, userId, entityType, entityId, direction);
Beispiel #20
0
        /// <summary>
        /// Vote for an item. Send the same value again to undo a vote.
        /// </summary>
        /// <param name="ident">The Id of the item to vote for</param>
        /// <param name="isAlbum">Flags declaring if the item is an album</param>
        /// <param name="vote">The vote to give</param>
        private async Task <ImgurResponse <Boolean> > VoteOnGalleryObjectAsync(string ident, bool isAlbum, VoteDirection vote)
        {
            if (ImgurClient.Authentication == null)
            {
                throw new InvalidAuthenticationException("Authentication can not be null. Set it in the main Imgur class.");
            }

            if (!(ImgurClient.Authentication is OAuth2Authentication))
            {
                throw new InvalidAuthenticationException("You need to use OAuth2Authentication to call this Endpoint.");
            }

            var endpoint = String.Format(isAlbum ? GalleryVoteAlbumUrl : GalleryVoteImageUrl, ident, vote.ToString().ToLowerInvariant());

            return
                (await
                 Request.SubmitImgurRequestAsync <Boolean>(Request.HttpMethod.Post, endpoint, ImgurClient.Authentication));
        }
Beispiel #21
0
		/// <summary>
		/// Vote on a comment
		/// </summary>
		/// <param name="commentId">The Id of the comment</param>
		/// <param name="vote">The vote to give the comment</param>
		public async Task<ImgurResponse<Boolean>> VoteCommentAsync(Int64 commentId, VoteDirection vote)
		{
			if (ImgurClient.Authentication == null)
				throw new InvalidAuthenticationException("Authentication can not be null. Set it in the main Imgur class.");

			if (!(ImgurClient.Authentication is OAuth2Authentication))
				throw new InvalidAuthenticationException("You need to use OAuth2Authentication to call this Endpoint.");

			return
				await
					Request.SubmitImgurRequestAsync<Boolean>(Request.HttpMethod.Get, String.Format(CommentVoteUrl, commentId, vote.ToString().ToLowerInvariant()),
						ImgurClient.Authentication);
		}
Beispiel #22
0
 public VoteOnComment(int commentId, VoteDirection voteDirection)
 {
     CommentId     = commentId;
     VoteDirection = voteDirection;
 }
Beispiel #23
0
 public async Task <IActionResult> VoteOnComment(int commentId, VoteDirection vote) =>
 (await mediator.Command(new VoteOnCommentCommand(new VoteOnComment(commentId, vote), User !))).Match(
Beispiel #24
0
 public VotePayload(VoteDirection direction, string steamID, byte[] authTicket)
 {
     SteamID   = steamID;
     Ticket    = string.Concat(Array.ConvertAll(authTicket, x => x.ToString("X2")));
     Direction = ((short)direction).ToString();
 }
Beispiel #25
0
 public Task VoteAsync(VoteDirection vote, int rank, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(Api.PostAsync(UrlConstants.VoteUrl, new { id = FullName, dir = (int)vote, rank },
                          cancellationToken));
 }
Beispiel #26
0
 public VotePayload(VoteDirection direction, string steamID, string authTicket)
 {
     SteamID   = steamID;
     Ticket    = authTicket;
     Direction = ((short)direction).ToString();
 }
Beispiel #27
0
        /// <summary>
        /// Vote on a comment
        /// </summary>
        /// <param name="commentId">The Id of the comment</param>
        /// <param name="vote">The vote to give the comment</param>
        public async Task <ImgurResponse <Boolean> > VoteCommentAsync(Int64 commentId, VoteDirection vote)
        {
            if (ImgurClient.Authentication == null)
            {
                throw new InvalidAuthenticationException("Authentication can not be null. Set it in the main Imgur class.");
            }

            if (!(ImgurClient.Authentication is OAuth2Authentication))
            {
                throw new InvalidAuthenticationException("You need to use OAuth2Authentication to call this Endpoint.");
            }

            return
                (await
                 Request.SubmitImgurRequestAsync <Boolean>(Request.HttpMethod.Get, String.Format(CommentVoteUrl, commentId, vote.ToString().ToLowerInvariant()),
                                                           ImgurClient.Authentication));
        }
Beispiel #28
0
 /// <summary>
 /// Converts the <see cref="VoteDirection"/> into an emoji
 /// </summary>
 /// <param name="direction">The direction (Up,Down) </param>
 /// <returns>An emoji :D</returns>
 public static string ToEmoji(this VoteDirection direction)
 {
     return(direction == VoteDirection.Up ? "👍" : "👎");
 }