Example #1
0
 public static VotePageState VoteReducer(VotePageState preVotePageState, VoteAction action)
 {
     preVotePageState.Items.Remove(action.Item);
     preVotePageState.CurrentItem = preVotePageState.NextItem;
     preVotePageState.NextItem    = preVotePageState.Items.SingleOrDefault();
     return(preVotePageState);
 }
Example #2
0
        public async Task <ActionResult <Question> > vote(int id, int option)
        {
            Question poll = await this._context.Questions
                            .Where(q => q.Id == id && q.additionalType == Question.GAME)
                            .Include("answers")
                            .FirstOrDefaultAsync();

            if (poll is null)
            {
                return(NotFound());
            }
            User user = this.HttpContext.Items["User"] as User;

            if (!(poll.answers.Find(v => v.agent.Id == user.Id) is null))
            {
                return(Conflict("Already voted"));
            }

            VoteAction vote = new VoteAction();

            vote.agent  = user;
            vote.answer = option;
            this._context.VoteActions.Add(vote);
            poll.answers.Add(vote);

            await this._context.SaveChangesAsync();

            return(poll);
        }
Example #3
0
    public void CreateVote(string voteString, UnityAction yesAction, UnityAction noAction)
    {
        voteAction = new VoteAction(yesAction, noAction);

        //MyNetwork.Instance.CreateVote(voteString);
        CommandProcessor.Instance.ExecuteClientCommand(new CommandCreateVote(voteString));
    }
Example #4
0
 private void TargetOnVoteResult(NetworkConnection connection, byte v)
 {
     if (voteAction != null)
     {
         voteAction.ExecuteAction((Vote.Options)v);
         voteAction = null;
     }
 }
Example #5
0
 /// <summary>
 /// Creates a new vote notify.
 /// </summary>
 /// <param name="buffer">A buffer contaning the packet data.</param>
 public IS_VTN(byte[] buffer)
     : this() {
     PacketReader reader = new PacketReader(buffer);
     Size = reader.ReadByte();
     Type = (PacketType)reader.ReadByte();
     ReqI = reader.ReadByte();
     reader.Skip(1);
     UCID = reader.ReadByte();
     Action = (VoteAction)reader.ReadByte();
 }
Example #6
0
            public override bool Equates(VoteAction a)
            {
                var action = a as MoveVoteAction;

                if (action == null)
                {
                    return(false);
                }
                return(X == action.X && Z == action.Z);
            }
Example #7
0
            public override bool Equates(VoteAction a)
            {
                var action = a as SpawnVoteAction;

                if (action == null)
                {
                    return(false);
                }
                return(X == action.X && Z == action.Z && EntityType == action.EntityType);
            }
Example #8
0
        /// <summary>
        /// Creates a new vote notify.
        /// </summary>
        /// <param name="buffer">A buffer contaning the packet data.</param>
        public IS_VTN(byte[] buffer)
            : this()
        {
            PacketReader reader = new PacketReader(buffer);

            Size = reader.ReadByte();
            Type = (PacketType)reader.ReadByte();
            ReqI = reader.ReadByte();
            reader.Skip(1);
            UCID   = reader.ReadByte();
            Action = (VoteAction)reader.ReadByte();
        }
Example #9
0
        public async Task <IActionResult> PostAsync(VoteAction voteAction)
        {
            var item = await _nodeService.GetAsync(voteAction.ItemId);

            var allowed = await _securityService.IsAllowedAsync(
                HttpContext.User, item.Module, item.Type, Actions.Vote);

            if (!allowed)
            {
                throw new Exception("User is not allowed to perform the action.");
            }
            var userId = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);

            return(Ok(await _nodeService.VoteAsync(userId, voteAction.ItemId, voteAction.IsUpVote)));
        }
        public async Task <int> AddAsync(string id, bool isUpVote)
        {
            var voteAction = new VoteAction()
            {
                ItemId   = id,
                IsUpVote = isUpVote
            };
            var response = await AuthorizedHttpClient.PostAsJsonAsync(API_URL, voteAction);

            var votes = await response.Content.ReadAsStringAsync();

            int output = 0;

            int.TryParse(votes, out output);
            return(output);
        }
Example #11
0
        private async Task OnReactionChanged(Cacheable <IUserMessage, ulong> cache, SocketReaction reaction, int direction)
        {
            IUserMessage message = await cache.DownloadAsync();

            if (message == null)
            {
                return;
            }

            if (reaction.Channel is SocketGuildChannel guildChannel && reaction.Emote is Emote emote)
            {
                if (emote.Id == _upvoteEmoteId.GetValue())
                {
                    VoteAction action = direction == 1 ? VoteAction.AddUpvote : VoteAction.RemoveUpvote;
                    ChangeKarma(reaction.User.Value, message.Channel, message, action);
                }

                if (emote.Id == _downvoteEmoteId.GetValue())
                {
                    VoteAction action = direction == 1 ? VoteAction.AddDownvote : VoteAction.RemoveDownvote;
                    ChangeKarma(reaction.User.Value, message.Channel, message, action);
                }
            }
        }
Example #12
0
 public void ChangeKarma(ulong guildId, ulong senderId, ulong recieverId, ulong channelId, ulong messageId, VoteAction action)
 {
     AddIfMissing(guildId, recieverId);
     _karma[recieverId].MutateValue(x => x.Vote(senderId, channelId, messageId, action));
 }
Example #13
0
 private void ChangeKarma(IUser giver, IMessageChannel channel, IUserMessage message, VoteAction action)
 {
     if (giver.Id == message.Author.Id)
     {
         return; // Can't go around giving yourself karma, ye twat.
     }
     _karmaRepo.ChangeKarma(GuildHandler.GuildId, giver.Id, message.Author.Id, channel.Id, message.Id, action);
 }
Example #14
0
 public abstract bool Equates(VoteAction argAction);