Exemple #1
0
        public int GetVoteCount()
        {
            var upVotes   = Votes.Count(vote => vote.Type == VoteType.UpVote);
            var downVotes = Votes.Count(vote => vote.Type == VoteType.DownVote);

            return(upVotes - downVotes);
        }
Exemple #2
0
        /// <summary>
        /// Vote the content data item by specified user name and value.
        /// </summary>
        /// <param name="userName">The user name.</param>
        /// <param name="value">The vote value.</param>
        /// <returns>A double value of average votes.</returns>
        public double Vote(string userName, int value)
        {
            if (this.CanVote(userName))
            {
                votes = null;
                Context.Add(new Vote()
                {
                    ObjectID = this.ID.ToString(),
                    UserName = userName,
                    Value    = value
                });
                Context.SaveChanges();
                this.Ratings     = AverageVotes;
                Model.Ratings    = this.Ratings;
                Model.TotalVotes = Votes.Count();
                this.TotalVotes  = Model.TotalVotes;
                Context.Update(Model);
                Context.SaveChanges();

                //EventDispatcher.RaiseContentDataItemVoted(this, userName, value, AverageVotes);
                this.Trigger("ContentDataItemVoted", new ContentDataItemVotedEventArgs()
                {
                    List = this.Parent, DataItem = this, Average = AverageVotes, UserName = userName, Votes = value
                });
            }
            return(AverageVotes);
        }
Exemple #3
0
        public void Finish()
        {
            AssertOnGoingVoting();
            var maxVotes = Votes.Select(y => y.Value).Max();

            AssertOnlyOneWinner();
            Winner = Votes.Single(x => x.Value == maxVotes).Key;

            void AssertOnlyOneWinner()
            {
                if (Votes.Count(x => x.Value == maxVotes) != 1)
                {
                    throw new InvalidOperationException("Can't finish voting, only one winner is allowed");
                }
            }
        }
Exemple #4
0
        public override string ToString()
        {
            var remaining = Finished - DateTime.Now;

            return($@"Vote to ban {FullName}{(DurationInHours <= (24*90) ? $" for {DurationInHours}h" : "")} due to ""{Reason}""{Environment.NewLine}{Votes.Count} votes ({Votes.Count(x => x.VotedFor)} votes for, {Votes.Count(x => !x.VotedFor)} votes against)" + (remaining > TimeSpan.Zero ? ", remaining time " + remaining.ToStringCustom(true) : ""));
        }
Exemple #5
0
        public async Task LoadAsync()
        {
            if (Poll == null)
            {
                return;
            }

            IList <Answer> answers;

            using (var service = Statics.NewService())
            {
                Votes = await service.GetVotesForPollAsync(Poll);

                answers = await service.GetAnswersForPollAsync(Poll);

                UsersCount = await service.GetUsersCountAsync();
            }

            Answers = new ObservableCollection <PollModel.AnswerWrapper>(answers
                                                                         .Select(a => new PollModel.AnswerWrapper(a,
                                                                                                                  Votes.Count(v => v.Answer.Id == a.Id),
                                                                                                                  Votes.Any(v => v.Answer.Id == a.Id && v.User.Id == Statics.CurrentUser.Id)))
                                                                         );

            CanVote           = Votes.All(v => v.User.Id != Statics.CurrentUser.Id);
            TransitionerIndex = CanVote ? 0 : 1;
        }
Exemple #6
0
        public override string ToString()
        {
            var remaining = Finished - DateTime.Now;

            return($@"Vote to restart server due to ""{Reason}""{Environment.NewLine}{Votes.Count} votes ({Votes.Count(x => x.VotedFor)} voted for, {Votes.Count(x => !x.VotedFor)} voted against)" + (remaining > TimeSpan.Zero ? ", remaining time " + remaining.ToStringCustom(true) : ""));
        }