Only update score timestamps when you get more points

This commit is contained in:
Slendy 2023-08-28 16:32:58 -05:00
parent 9f5a85d600
commit f0a1826b85
No known key found for this signature in database
GPG key ID: 7288D68361B91428
2 changed files with 171 additions and 8 deletions

View file

@ -136,14 +136,10 @@ public class ScoreController : ControllerBase
.Where(s => s.UserId == token.UserId)
.Where(s => s.Type == score.Type)
.FirstOrDefaultAsync();
if (existingScore != null)
if (existingScore == null)
{
existingScore.Points = Math.Max(existingScore.Points, score.Points);
existingScore.Timestamp = TimeHelper.TimestampMillis;
}
else
{
ScoreEntity playerScore = new()
existingScore = new ScoreEntity
{
UserId = token.UserId,
Type = score.Type,
@ -152,7 +148,13 @@ public class ScoreController : ControllerBase
ChildSlotId = childId,
Timestamp = TimeHelper.TimestampMillis,
};
this.database.Scores.Add(playerScore);
this.database.Scores.Add(existingScore);
}
if (score.Points > existingScore.Points)
{
existingScore.Points = score.Points;
existingScore.Timestamp = TimeHelper.TimestampMillis;
}
await this.database.SaveChangesAsync();