From 13ad0ff4f3bce05e513768d4999a3f4ec471b872 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 2 May 2017 16:03:32 -0400 Subject: Pong highscore frontend. --- Project-Unite/Controllers/StatsController.cs | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Project-Unite/Controllers/StatsController.cs (limited to 'Project-Unite/Controllers/StatsController.cs') diff --git a/Project-Unite/Controllers/StatsController.cs b/Project-Unite/Controllers/StatsController.cs new file mode 100644 index 0000000..71d2adc --- /dev/null +++ b/Project-Unite/Controllers/StatsController.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Web; +using System.Web.Mvc; +using Project_Unite.Models; + +namespace Project_Unite.Controllers +{ + public class StatsController : Controller + { + // GET: Stats + public ActionResult Pong(int id = 1) + { + var db = new ApplicationDbContext(); + var highscores = new List(); + foreach(var user in db.Users) + { + highscores.Add(new PongHighscore + { + UserId = user.Id, + Level = user.Pong_HighestLevel, + CodepointsCashout = user.Pong_HighestCodepointsCashout + }); + } + + int pagecount = highscores.GetPageCount(10); + if (id > pagecount || id < 1) + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + + var pages = highscores.OrderByDescending(x=>x.Level).ToArray().GetItemsOnPage(id, 10); + + var model = new PongStatsViewModel + { + Highscores = pages, + CurrentPage = id, + PageCount = 10 + }; + + return View(model); + } + } +} \ No newline at end of file -- cgit v1.2.3