From 6356ddc7c69c63171dd2ea25db12242747503d07 Mon Sep 17 00:00:00 2001 From: Elton Stoneman Date: Wed, 26 Sep 2018 11:58:32 +0100 Subject: [PATCH] Fix initial load --- result/dotnet/Result/Data/MySqlResultData.cs | 4 ++-- result/dotnet/Result/Pages/Index.cshtml | 4 ++-- result/dotnet/Result/wwwroot/js/results.js | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/result/dotnet/Result/Data/MySqlResultData.cs b/result/dotnet/Result/Data/MySqlResultData.cs index 8a1cbbe..3c8ed67 100644 --- a/result/dotnet/Result/Data/MySqlResultData.cs +++ b/result/dotnet/Result/Data/MySqlResultData.cs @@ -26,11 +26,11 @@ namespace Result.Data var results = connection.Query("SELECT vote, COUNT(id) AS count FROM votes GROUP BY vote ORDER BY vote"); if (results.Any(x => x.vote == "a")) { - model.OptionA = results.First(x => x.vote == "a").count; + model.OptionA = (int) results.First(x => x.vote == "a").count; } if (results.Any(x => x.vote == "b")) { - model.OptionB = results.First(x => x.vote == "b").count; + model.OptionB = (int) results.First(x => x.vote == "b").count; } model.VoteCount = model.OptionA + model.OptionB; } diff --git a/result/dotnet/Result/Pages/Index.cshtml b/result/dotnet/Result/Pages/Index.cshtml index 21a992a..4b3dcdf 100644 --- a/result/dotnet/Result/Pages/Index.cshtml +++ b/result/dotnet/Result/Pages/Index.cshtml @@ -26,12 +26,12 @@
@Model.OptionA
-
+
50%
@Model.OptionB
-
+
50%
diff --git a/result/dotnet/Result/wwwroot/js/results.js b/result/dotnet/Result/wwwroot/js/results.js index 015d5bf..e08e90d 100644 --- a/result/dotnet/Result/wwwroot/js/results.js +++ b/result/dotnet/Result/wwwroot/js/results.js @@ -11,10 +11,11 @@ connection.on("UpdateResults", function (results) { document.getElementById("optionA").innerText = percentages.a + "%"; document.getElementById("optionB").innerText = percentages.b + "%"; + var totalVotes = 'No votes yet'; if (results.voteCount > 0) { - var totalVotes = results.voteCount + (results.voteCount > 1 ? " votes" : " vote"); - document.getElementById("totalVotes").innerText = totalVotes; + totalVotes = results.voteCount + (results.voteCount > 1 ? " votes" : " vote"); } + document.getElementById("totalVotes").innerText = totalVotes; var bg1 = document.getElementById('background-stats-1'); var bg2 = document.getElementById('background-stats-2');