Exemplo n.º 1
0
        public void RemoveOption(int optionId)
        {
            PollOption optionToRemove = (from targetOption in this.Options
                                         where targetOption.Id == optionId
                                         select targetOption).Single();

            if (optionToRemove != null)
            {
                this.Options.Remove(optionToRemove);
            }
        }
Exemplo n.º 2
0
        public PollOption AddOption(string optionText)
        {
            PollOption newItem = new PollOption();

            newItem.OptionText = optionText;

            if (this.Options == null)
            {
                this.Options = new List <PollOption>();
            }

            this.Options.Add(newItem);
            return(newItem);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add a vote for a poll option
        /// </summary>
        /// <param name="pollOptionId"></param>
        /// <param name="address"></param>
        /// <returns>The poll question with the additional vote</returns>
        public void AddOptionVote(int pollOptionId, IPAddress address)
        {
            PollOption previousVote = (from targetOption in this.Options
                                       where targetOption.VoterAddresses.Any(var => var.Address == address)
                                       select targetOption).Single();

            if (previousVote != null)
            {
                VoterAddress voterAddress = (from addressItem in previousVote.VoterAddresses where addressItem.Address == address select addressItem).Single();
                previousVote.VoterAddresses.Remove(voterAddress);
            }

            PollOption votedOption = (from targetOption in this.Options where targetOption.Id == pollOptionId select targetOption).First();

            if (votedOption != null)
            {
                votedOption.VoterAddresses.Add(new VoterAddress(address));
            }
        }