Created
June 7, 2011 11:13
-
-
Save SteveSanderson/1012046 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 VotingController : TaskAsyncController | |
{ | |
static TaskCompletionSource<bool> hasNewVote = new TaskCompletionSource<bool>(); | |
// Could load this from a DB | |
static Question question = new Question { | |
QuestionText = "What's your favourite upcoming technology?", | |
Answers = new List<Answer> { | |
new Answer { AnswerId = 1, AnswerText = "C# 5" }, | |
new Answer { AnswerId = 2, AnswerText = "WebSockets" }, | |
new Answer { AnswerId = 3, AnswerText = "Windows 8" }, | |
new Answer { AnswerId = 5, AnswerText = "Magic rainbow unicorns" }, | |
} | |
}; | |
public ActionResult Index() | |
{ | |
return View(question); | |
} | |
public void SubmitVote(int answerId) | |
{ | |
question.Answers.Single(x => x.AnswerId == answerId).NumVotes++; | |
hasNewVote.SetResult(true); | |
hasNewVote = new TaskCompletionSource<bool>(); | |
} | |
public Task<JsonResult> GetUpdatedState() | |
{ | |
return hasNewVote.Task.ContinueWith(_ => | |
{ | |
return Json(question); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment