コード例 #1
0
        public async Task <IActionResult> SetVote([FromRoute] Guid postId, [FromBody] VoteValue voteValue)
        {
            if (voteValue == null)
            {
                return(BadRequest());
            }
            var value = voteValue.Value;

            if (value < -1 || value > 1)
            {
                return(BadRequest());
            }

            // Super simple voting system. Voting up is worth more than voting down.
            var votes = 0;

            if (value == -1)
            {
                votes = -2;
            }
            if (value == 1)
            {
                votes = 10;
            }

            var difference = await _votesRepository.VoteAsync(this.GetUserLoginInfo(), postId, votes);

            return(Json(new
            {
                Difference = difference
            }));
        }
コード例 #2
0
        public OperationResultVo Vote(Guid userId, Guid ideaId, VoteValue vote)
        {
            try
            {
                BrainstormVote model;
                BrainstormIdea idea = brainstormDomainService.GetIdea(ideaId);

                BrainstormVote existing = idea.Votes.FirstOrDefault(x => x.UserId == userId);
                if (existing != null)
                {
                    model           = existing;
                    model.VoteValue = vote;
                }
                else
                {
                    model = new BrainstormVote
                    {
                        UserId    = userId,
                        IdeaId    = ideaId,
                        SessionId = idea.SessionId,
                        VoteValue = vote
                    };
                }

                if (model.Id == Guid.Empty)
                {
                    brainstormDomainService.AddVote(model);
                }
                else
                {
                    brainstormDomainService.UpdateVote(model);
                }

                unitOfWork.Commit();

                return(new OperationResultVo <Guid>(model.Id));
            }
            catch (Exception ex)
            {
                return(new OperationResultVo <Guid>(ex.Message));
            }
        }
コード例 #3
0
        public async Task VoteAsync(string userId, int id, VoteValue vote)
        {
            var userVote = await this.db.Votes.FirstOrDefaultAsync(v => v.UserId == userId && v.BookId == id);

            if (userVote == null)
            {
                this.db.Add(new Vote
                {
                    BookId    = id,
                    UserId    = userId,
                    VoteValue = vote
                });
            }
            else if (userVote.VoteValue == vote)
            {
                userVote.VoteValue = null;
            }
            else
            {
                userVote.VoteValue = vote;
            }

            await this.db.SaveChangesAsync();
        }
コード例 #4
0
 public VotePostCommand(int postId, VoteValue vote)
 {
     Vote   = vote;
     PostId = postId;
 }
コード例 #5
0
ファイル: Vote.cs プロジェクト: garunski/Lunchage
 public Vote(VoteValue voteValue, LunchSelection selection)
 {
     this.value = voteValue;
     this.selection = selection;
 }