Tye is a tool that makes developing, testing, and deploying microservices and distributed applications easier. Project Tye includes a local orchestrator to make developing microservices easier and the ability to deploy microservices to Kubernetes with min
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

51 lines
1.5 KiB

using System;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using StackExchange.Redis;
namespace Vote.Pages
{
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
private IConnectionMultiplexer _redisConnection;
public IConfiguration Configuration { get; set; }
[BindProperty()]
public string Vote {get;set;}
public IndexModel(ILogger<IndexModel> logger, IConfiguration configuration, IConnectionMultiplexer redisConnection)
{
_logger = logger;
Configuration = configuration;
_redisConnection = redisConnection;
}
public async Task OnPost()
{
try
{
var voterId = TempData.Peek("VoterId");
if (voterId == null)
{
voterId = Guid.NewGuid();
TempData["VoterId"] = voterId;
}
var data = JsonSerializer.Serialize(new { voterId = voterId, vote = Vote });
var database = _redisConnection.GetDatabase();
_logger.LogInformation($"pushing {data}");
await database.ListRightPushAsync("votes", data);
}
catch(Exception ex)
{
_logger.LogError(ex, "Error submitting vote.");
}
}
}
}