public async Task VoteOnPoll(NewVoteOptions voteOptions) { Account _account = new(); if (Context.Items.ContainsKey("account")) { Account account = (Account)Context.Items["account"]; _account = _unitOfWork.Account.GetById(account.Id.ToString()); } _unitOfWork.Poll.VotePoll(_account, voteOptions); _unitOfWork.SaveChanges(); await Clients.Caller.ReceivePollResults(_unitOfWork.Poll.GetPollResults()); }
public void VotePoll(Account account, NewVoteOptions newVote) { Poll poll = GetLatestPoll(); if (poll.Name == "NOLATESTPOLL") { return; } List <PollOption> options = poll.Options; foreach (string voteOption in newVote.VoteOptions) { PollOption?option = options.Find(pollOption => pollOption.Id.ToString() == voteOption); poll.Votes.Add(new PollVote { Account = account, PollOption = option, TimeStamp = DateTime.Now }); } }