Created
March 23, 2021 14:32
-
-
Save ry8806/fda8b77068d3800bb10e069a5ddb3731 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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