Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChartManager" /> class.
 /// </summary>
 /// <param name="voteResultChartVM">voteResultChart view model</param>
 /// <param name="dataContext">data context</param>
 /// <param name="ipollManager">poll manager</param>
 /// <param name="kernel">DI kernel</param>
 public ChartManager(IVoteResultChartVM voteResultChartVM, VoteContext dataContext, IPollManager ipollManager, IKernel kernel)
 {
     this.voteResultChartVM = voteResultChartVM;
     this.context           = dataContext;
     this.ipollManager      = ipollManager;
     this.krnel             = kernel;
 }
Example #2
0
        /// <summary>
        /// Get all the resolution for the poll
        /// </summary>
        /// <param name="questionId">question id</param>
        /// <param name="pollId">poll id</param>
        /// <returns>returns poll result view model</returns>
        private IVoteResultChartVM GetResolution(int questionId, int pollId)
        {
            var pollStat = this.context.Poll_Statistics.Where(x => x.QuestionID == questionId);
            IVoteResultChartVM chartVM = this.krnel.Get <IVoteResultChartVM>();

            ////1.  Get the description
            chartVM.ResolutionDescription = this.context.Poll_Questions.FirstOrDefault(x => x.QuestionID == questionId).QuestionDescription;

            ////2.  Get the Favour
            var dataFavour = (from a in this.context.Poll_Statistics
                              join b in this.context.Poll_Options on a.OptionID equals b.OptionID
                              where b.OptionName == "In Favour" && a.QuestionID == questionId
                              select a.TotalVotes).ToList();

            chartVM.Favour = dataFavour != null && dataFavour.Count() > 0 ? Convert.ToInt32(dataFavour[0]) : 0;

            ////3.  Get the Against
            chartVM.Against = (from a in this.context.Poll_Statistics
                               join b in this.context.Poll_Options on a.OptionID equals b.OptionID
                               where b.OptionName == "Against" && a.QuestionID == questionId
                               select a.TotalVotes).ToList().FirstOrDefault() ?? 0;

            ////4.  Get the Abstain
            chartVM.Abstain = (from a in this.context.Poll_Statistics
                               join b in this.context.Poll_Options on a.OptionID equals b.OptionID
                               where b.OptionName == "Abstain" && a.QuestionID == questionId
                               select a.TotalVotes).ToList().FirstOrDefault() ?? 0;

            ////5.  Get not voted yet
            chartVM.NotVoted = Convert.ToInt32(this.context.Poll_Maintenance.FirstOrDefault(x => x.PollId == pollId).TotalVotesExpected) -
                               (chartVM.Favour + chartVM.Against + chartVM.Abstain);

            return(chartVM);
        }