protected void Page_Load(object sender, EventArgs e) { if (Page.Request.HttpMethod == "POST") { string name = (Request.Form["Name"]); string score = (Request.Form["Score"]); try { using (var db = new FallDownContext()) { HighScore highScore = new HighScore { Name = name, Score = Convert.ToInt32(score), InsertDatetime = DateTime.Now }; db.AddToHighScores(highScore); db.SaveChanges(); } Response.Clear(); Response.ContentType = "application/text; charset=utf-8"; Response.Write("True"); Response.End(); } catch (Exception ex) { Response.Clear(); Response.ContentType = "application/text; charset=utf-8"; Response.Write("False"); Response.End(); throw ex; } } }
protected void Page_Load(object sender, EventArgs e) { if (Page.Request.HttpMethod == "POST") { int n = Convert.ToInt32((Request.Form["Number"])); List <HighScore> topNScores = new List <HighScore>(); using (var db = new FallDownContext()) { var query = (from hs in db.HighScores orderby hs.Score select hs).Take(n); foreach (var score in query) { topNScores.Add(score); } } Response.Clear(); Response.ContentType = "application/text; charset=utf-8"; Response.Write(topNScores); Response.End(); } }
protected void Page_Load(object sender, EventArgs e) { if (Page.Request.HttpMethod == "POST") { string initials = (Request.Form["Initials"]); string score = (Request.Form["Score"]); using (var db = new FallDownContext()) { HighScore highScore = new HighScore { Name = "ZZZ", Score = Convert.ToInt32("23"), InsertDatetime = DateTime.Now }; db.HighScores.Add(highScore); db.SaveChanges(); } Response.Clear(); Response.ContentType = "application/text; charset=utf-8"; Response.Write("Total Score: 200"); Response.End(); } }