From 733d9992d504715b11314e405a012dca771ee129 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 2 May 2017 16:06:40 -0400 Subject: [PATCH] pong highscore API --- Project-Unite/Controllers/APIController.cs | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/Project-Unite/Controllers/APIController.cs b/Project-Unite/Controllers/APIController.cs index 9d22a75..b9cdcbe 100644 --- a/Project-Unite/Controllers/APIController.cs +++ b/Project-Unite/Controllers/APIController.cs @@ -12,6 +12,81 @@ namespace Project_Unite.Controllers { public class APIController : Controller { + public ActionResult GetPongCP() + { + try + { + string token = Request.Headers["Authentication"].Remove(0, 6); + var user = ACL.GetUserFromToken(token); + if (user == null) + return new HttpStatusCodeResult(HttpStatusCode.Forbidden); + return Content(user.Pong_HighestCodepointsCashout.ToString()); + } + catch + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + } + + public ActionResult SetPongCP(int id) + { + try + { + string token = Request.Headers["Authentication"].Remove(0, 6); + + var db = new ApplicationDbContext(); + var t = db.OAuthTokens.FirstOrDefault(x => x.Id == token); + var user = db.Users.FirstOrDefault(x => x.Id == t.UserId); + user.Pong_HighestCodepointsCashout = id; + db.SaveChanges(); + return new HttpStatusCodeResult(200); + } + catch + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + } + + + public ActionResult GetPongLevel() + { + try + { + string token = Request.Headers["Authentication"].Remove(0, 6); + var user = ACL.GetUserFromToken(token); + if (user == null) + return new HttpStatusCodeResult(HttpStatusCode.Forbidden); + return Content(user.Pong_HighestLevel.ToString()); + } + catch + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + } + + public ActionResult SetPongLevel(int id) + { + try + { + string token = Request.Headers["Authentication"].Remove(0, 6); + + var db = new ApplicationDbContext(); + var t = db.OAuthTokens.FirstOrDefault(x => x.Id == token); + var user = db.Users.FirstOrDefault(x => x.Id == t.UserId); + + user.Pong_HighestLevel = id; + db.SaveChanges(); + return new HttpStatusCodeResult(200); + } + catch + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + } + + + + public ActionResult GetCodepoints() { try