private void DoNext() { CurrentQuestion++; var page = Questions[CurrentQuestion - 1]; TransitionView.ShowPage(page); }
private void DoPrev() { CurrentQuestion--; var page = Questions[CurrentQuestion - 1]; TransitionView.ShowPage(page, false); }
private async Task GetVoteDetails() { var questions = await MultiChainVm.Model.GetQuestions(); var questionVMs = questions.Select(q => new QuestionViewModel(this) { QuestionNumber = q.Number, Question = q.Question, Answers = q.Answers.Select(a => new AnswerViewModel { Answer = a.Answer, Info = a.Info }).ToList() }).ToList(); Ui(() => { Loading = false; Questions.Clear(); Questions.AddRange(questionVMs); TotalQuestions = questionVMs.Count; CurrentQuestion = 1; TransitionView.ShowPage(Questions.First()); }); }
private void ShowPage(bool forwards = true) { var page = Results[CurrentResults - 1]; TransitionView.ShowPage(page, forwards); }
private async Task GetResults(BlockchainDetails blockchain) { // Ensure the blockchain is up to date var progressModel = new Progress <BlockchainSyncProgress>(UpdateProgress); await MultiChainVm.Model.WaitUntilBlockchainSynced(blockchain.Blocks, progressModel); try { // Read the questions from the blockchain _questions = await MultiChainVm.Model.GetQuestions(); var decryptKey = ""; // Blockchain encrypted, so we need the decryption key to read the results if (blockchain.ShouldEncryptResults) { decryptKey = await _voteClient.GetDecryptKey(blockchain.ChainString); } // Get answers from blockchain _answers = await MultiChainVm.Model.GetResults(blockchain.WalletId, decryptKey); // For each question, get its total for each answer var results = _questions.Select(question => { // Setup response dictionary, answer -> num votes var options = question.Answers.ToDictionary(a => a.Answer, a => 0); foreach (var answer in _answers) { foreach (var questionAnswer in answer.Answers.Where(a => a.Question == question.Number)) { // In case we have anything unusual going on if (!options.ContainsKey(questionAnswer.Answer)) { Debug.WriteLine( $"Unexpected answer for question {questionAnswer.Question}: {questionAnswer.Answer}"); continue; } options[questionAnswer.Answer]++; } } return(new { question.Number, question.Question, Results = options }); }).ToList(); var chartVms = results.Select(q => new ChartViewModel(q.Results) { Question = q.Question }).ToList(); Ui(() => { Loading = false; Results.Clear(); Results.AddRange(chartVms); TotalResults = chartVms.Count; CurrentResults = 1; TransitionView.ShowPage(Results.First()); }); } catch (Exception e) { Debug.WriteLine(e); } }