Add .NET Core 2.1 versions
This commit is contained in:
50
vote/dotnet/Vote/Pages/Index.cshtml
Normal file
50
vote/dotnet/Vote/Pages/Index.cshtml
Normal file
@ -0,0 +1,50 @@
|
||||
@page
|
||||
@model Vote.Pages.IndexModel
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>@Model.OptionA vs @Model.OptionB!</title>
|
||||
<base href="/index.html">
|
||||
<meta name="viewport" content="width=device-width, initial-scale = 1.0">
|
||||
<meta name="keywords" content="docker-compose, docker, stack">
|
||||
<meta name="author" content="Docker DevRel team">
|
||||
<link rel="stylesheet" href="~/css/site.css" />
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="content-container">
|
||||
<div id="content-container-center">
|
||||
<h3>@Model.OptionA vs @Model.OptionB!</h3>
|
||||
<form method="POST" id="choice" name='form'>
|
||||
<button id="a" type="submit" name="vote" class="a" value="a">@Model.OptionA</button>
|
||||
<button id="b" type="submit" name="vote" class="b" value="b">@Model.OptionB</button>
|
||||
</form>
|
||||
<div id="tip">
|
||||
(Tip: you can change your vote)
|
||||
</div>
|
||||
<div id="hostname">
|
||||
Processed by container ID @System.Environment.MachineName
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="~/js/jquery-1.11.1-min.js" type="text/javascript"></script>
|
||||
@*<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>*@
|
||||
|
||||
<script>
|
||||
var vote = "@Model.Vote";
|
||||
|
||||
if(vote == "a"){
|
||||
$(".a").prop('disabled', true);
|
||||
$(".a").html('@Model.OptionA <i class="fa fa-check-circle"></i>');
|
||||
$(".b").css('opacity','0.5');
|
||||
}
|
||||
if(vote == "b"){
|
||||
$(".b").prop('disabled', true);
|
||||
$(".b").html('@Model.OptionB <i class="fa fa-check-circle"></i>');
|
||||
$(".a").css('opacity','0.5');
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
75
vote/dotnet/Vote/Pages/Index.cshtml.cs
Normal file
75
vote/dotnet/Vote/Pages/Index.cshtml.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Vote.Messaging;
|
||||
using Vote.Messaging.Messages;
|
||||
|
||||
namespace Vote.Pages
|
||||
{
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
private string _optionA;
|
||||
private string _optionB;
|
||||
|
||||
protected readonly IMessageQueue _messageQueue;
|
||||
protected readonly IConfiguration _configuration;
|
||||
protected readonly ILogger _logger;
|
||||
|
||||
public IndexModel(IMessageQueue messageQueue, IConfiguration configuration, ILogger<IndexModel> logger)
|
||||
{
|
||||
_messageQueue = messageQueue;
|
||||
_configuration = configuration;
|
||||
_logger = logger;
|
||||
|
||||
_optionA = _configuration.GetValue<string>("Voting:OptionA");
|
||||
_optionB = _configuration.GetValue<string>("Voting:OptionB");
|
||||
}
|
||||
|
||||
public string OptionA { get; private set; }
|
||||
|
||||
public string OptionB { get; private set; }
|
||||
|
||||
[BindProperty]
|
||||
public string Vote { get; private set; }
|
||||
|
||||
private string _voterId
|
||||
{
|
||||
get { return TempData.Peek("VoterId") as string; }
|
||||
set { TempData["VoterId"] = value; }
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
OptionA = _optionA;
|
||||
OptionB = _optionB;
|
||||
}
|
||||
|
||||
public IActionResult OnPost(string vote)
|
||||
{
|
||||
Vote = vote;
|
||||
OptionA = _optionA;
|
||||
OptionB = _optionB;
|
||||
if (_configuration.GetValue<bool>("MessageQueue:Enabled"))
|
||||
{
|
||||
PublishVote(vote);
|
||||
}
|
||||
return Page();
|
||||
}
|
||||
|
||||
private void PublishVote(string vote)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_voterId))
|
||||
{
|
||||
_voterId = Guid.NewGuid().ToString();
|
||||
}
|
||||
var message = new VoteCastEvent
|
||||
{
|
||||
VoterId = _voterId,
|
||||
Vote = vote
|
||||
};
|
||||
_messageQueue.Publish(message);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user