From 6b35545286760676741c4839c1e6f598c5ea8785 Mon Sep 17 00:00:00 2001 From: LumaLivy Date: Mon, 8 Nov 2021 05:14:14 -0500 Subject: [PATCH] Increment completion count on score submission --- ProjectLighthouse/Controllers/ScoreController.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ProjectLighthouse/Controllers/ScoreController.cs b/ProjectLighthouse/Controllers/ScoreController.cs index b9695f9e..1b6314bd 100644 --- a/ProjectLighthouse/Controllers/ScoreController.cs +++ b/ProjectLighthouse/Controllers/ScoreController.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using System.Xml.Serialization; using LBPUnion.ProjectLighthouse.Serialization; using LBPUnion.ProjectLighthouse.Types; +using LBPUnion.ProjectLighthouse.Types.Levels; using Microsoft.AspNetCore.Mvc; namespace LBPUnion.ProjectLighthouse.Controllers @@ -25,7 +26,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers } [HttpPost("scoreboard/user/{id:int}")] - public async Task SubmitScore(int id) + public async Task SubmitScore(int id, [FromQuery] bool lbp1 = false, [FromQuery] bool lbp2 = false, [FromQuery] bool lbp3 = false) { User? user = await this.database.UserFromRequest(this.Request); if (user == null) return this.StatusCode(403, ""); @@ -39,8 +40,14 @@ namespace LBPUnion.ProjectLighthouse.Controllers score.SlotId = id; - IQueryable existingScore = this.database.Scores.Where(s => s.SlotId == score.SlotId && s.PlayerIdCollection == score.PlayerIdCollection); + Slot? slot = this.database.Slots.FirstOrDefault(s => s.SlotId == score.SlotId); + if (slot == null) return this.BadRequest(); + if (lbp1) slot.PlaysLBP1Complete++; + if (lbp2) slot.PlaysLBP2Complete++; + if (lbp3) slot.PlaysLBP3Complete++; + IQueryable existingScore = this.database.Scores.Where(s => s.SlotId == score.SlotId && s.PlayerIdCollection == score.PlayerIdCollection); + if (existingScore.Any()) { Score first = existingScore.First(s => s.SlotId == score.SlotId); @@ -52,6 +59,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers { this.database.Scores.Add(score); } + await this.database.SaveChangesAsync(); string myRanking = await GetScores(score.SlotId, score.Type, user);