Skip to content

Instantly share code, notes, and snippets.

@ry8806
Created March 23, 2021 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ry8806/fda8b77068d3800bb10e069a5ddb3731 to your computer and use it in GitHub Desktop.
Save ry8806/fda8b77068d3800bb10e069a5ddb3731 to your computer and use it in GitHub Desktop.
public class HomeController : Controller
{
private readonly BufferBlock<CompetitionEntry> _bufferBlock;
private readonly ILogger<HomeController> _logger;
public HomeController(BufferBlock<CompetitionEntry> bufferBlock, ILogger<HomeController> logger)
{
_bufferBlock = bufferBlock;
_logger = logger;
}
public IActionResult Index()
{
return View();
}
[HttpPost("enter")]
public async Task<IActionResult> SubmitEntry([FromBody] CompetitionEntryRequest entry)
{
// Sanitise the input
entry.Email = entry.Email.Trim();
// Create the object, from the model
var newEntry = new CompetitionEntry
{
Email = entry.Email,
Answer = entry.Answer,
Created = DateTime.UtcNow,
IPAddress = HttpContext.Connection.RemoteIpAddress ?? HttpContext.Connection.LocalIpAddress
};
// "Queue" the message on the Buffer Block
await _bufferBlock.SendAsync(newEntry);
return Ok();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment