示例#1
0
        public async Task <PollVotingResultModel> GetVotingResults(int pollId)
        {
            PollVotingResultModel pollResults = new PollVotingResultModel();

            pollResults = await GetPollBasicInfoAndAddToModel(pollId, pollResults);

            pollResults = await GetOptionsAndVotesFromDatabaseAndAddToModel(pollId, pollResults);

            return(pollResults);
        }
示例#2
0
        private async Task <PollVotingResultModel> AddOptionsAndVotesToModel(PollVotingResultModel pollResults, List <PollOptionModel> tempOptions)
        {
            foreach (var item in tempOptions)
            {
                OptionWithVotesModel optionWithVotes = new OptionWithVotesModel()
                {
                    Option = item
                };

                var tempVotes = await _voteRepo.GetVotesByOptionId(item.Id);

                if (tempVotes != null)
                {
                    optionWithVotes.Votes = tempVotes;
                }

                pollResults.Options.Add(optionWithVotes);
            }

            return(pollResults);
        }
示例#3
0
        private async Task <PollVotingResultModel> GetPollBasicInfoAndAddToModel(int pollId, PollVotingResultModel pollResults)
        {
            var tempPoll = await _pollRepo.GetBasicPoll(pollId);

            if (tempPoll == null)
            {
                pollResults.Poll = new PollModel();
            }
            else
            {
                pollResults.Poll = tempPoll;
            }

            return(pollResults);
        }
示例#4
0
        private async Task <PollVotingResultModel> GetOptionsAndVotesFromDatabaseAndAddToModel(int pollId, PollVotingResultModel pollResults)
        {
            var tempOptions = await _optionRepo.GetPollOptionsForDisplay(pollId);

            if (tempOptions != null)
            {
                pollResults = await AddOptionsAndVotesToModel(pollResults, tempOptions);
            }

            return(pollResults);
        }