From 96cde6df23dd611054177cb90da90df2211e7f02 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 3 May 2017 08:54:07 -0400 Subject: [PATCH] More pong highscore backend. --- Project-Unite/Controllers/APIController.cs | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Project-Unite/Controllers/APIController.cs b/Project-Unite/Controllers/APIController.cs index b9cdcbe..1c96422 100644 --- a/Project-Unite/Controllers/APIController.cs +++ b/Project-Unite/Controllers/APIController.cs @@ -174,7 +174,43 @@ public ActionResult SetSysName(string id) } } + public ActionResult GetPongHighscores() + { + try + { + string token = Request.Headers["Authentication"].Remove(0, 6); + var user = ACL.GetUserFromToken(token); + if (user == null) + return new HttpStatusCodeResult(HttpStatusCode.Forbidden); + var db = new ApplicationDbContext(); + var highscores = new List(); + foreach (var u in db.Users) + { + highscores.Add(new PongHighscore + { + UserId = u.Id, + Level = u.Pong_HighestLevel, + CodepointsCashout = u.Pong_HighestCodepointsCashout + }); + } + int pagecount = highscores.GetPageCount(10); + var pages = highscores.OrderByDescending(x => x.Level).ToArray(); + + var model = new PongStatsViewModel + { + Highscores = pages.ToList(), + CurrentPage = 0, + PageCount = 10 + }; + + return Content(Serializer.Serialize(model)); + } + catch + { + return new HttpStatusCodeResult(403); + } + } public ActionResult GetDisplayName()