Esempio n. 1
0
 public void Reveal()
 {
     if (Votes != null && Votes.Any())
     {
         WonBy = Votes.GroupBy(i => i)
                 .Select(i => new { PlayerId = i.Key, Count = i.Count() })
                 .OrderByDescending(i => i.Count)?
                 .FirstOrDefault()?.PlayerId ?? 0;
     }
 }
Esempio n. 2
0
        public IReadOnlyCollection <string> CanVote(int userId)
        {
            Collection <string> errors = new Collection <string>();

            if (Votes.Any(x => x.User.Id == userId))
            {
                errors.Add("Só é possível votar em um restaurante por dia");
            }
            if (DateTime.Now > ClosingTime)
            {
                errors.Add("Eleição já foi encerrada");
            }

            return(errors);
        }
Esempio n. 3
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;
        }
Esempio n. 4
0
 public bool IsRated(string userId, Guid recipeId)
 {
     return(Votes.Any(v => v.UserId == userId && v.RecipeId == recipeId));
 }
Esempio n. 5
0
 private bool HasUpvoteFromUser(User user)
 {
     return(user != null &&
            Votes.Any(v => v.VoterId == user.Id && v.Value == 1));
 }